blob: 752e44da0ede3d7722ebba92ab064984dbc091bc [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;
Tunahan Sezenf0843b92021-04-30 07:13:16 +000037import org.onosproject.net.AnnotationKeys;
38import org.onosproject.net.DefaultAnnotations;
39import org.onosproject.net.DefaultPort;
Andrea Campanellacbbb7952019-11-25 06:38:41 +000040import org.onosproject.net.DeviceId;
41import org.onosproject.net.MastershipRole;
42import org.onosproject.net.PortNumber;
43import org.onosproject.net.flow.TrafficSelector;
44import org.onosproject.net.flow.TrafficTreatment;
45import org.onosproject.net.flow.criteria.Criterion;
46import org.onosproject.net.flow.criteria.EthTypeCriterion;
47import org.onosproject.net.flow.criteria.PortCriterion;
48import org.onosproject.net.flow.criteria.VlanIdCriterion;
49import org.onosproject.net.flow.instructions.Instruction;
50import org.onosproject.net.flow.instructions.Instructions;
51import org.onosproject.net.flow.instructions.L2ModificationInstruction;
52import org.onosproject.net.flowobjective.FilteringObjQueueKey;
53import org.onosproject.net.flowobjective.FilteringObjective;
54import org.onosproject.net.flowobjective.ForwardingObjQueueKey;
55import org.onosproject.net.flowobjective.ForwardingObjective;
56import org.onosproject.net.flowobjective.NextObjQueueKey;
57import org.onosproject.net.flowobjective.NextObjective;
58import org.onosproject.net.flowobjective.Objective;
59import org.onosproject.net.meter.MeterId;
60import org.onosproject.net.meter.MeterKey;
Tunahan Sezenf0843b92021-04-30 07:13:16 +000061import org.opencord.olt.AccessDevicePort;
Andrea Campanellacbbb7952019-11-25 06:38:41 +000062import org.opencord.sadis.BandwidthProfileInformation;
63import org.opencord.sadis.UniTagInformation;
64
Saurav Dasf62cea82020-08-26 17:43:04 -070065import com.google.common.collect.ImmutableList;
66import com.google.common.collect.ImmutableMap;
67import com.google.common.collect.ImmutableSet;
68import com.google.common.collect.ListMultimap;
Andrea Campanellacbbb7952019-11-25 06:38:41 +000069
70public class OltFlowTest extends TestBase {
71 private OltFlowService oltFlowService;
Tunahan Sezenf0843b92021-04-30 07:13:16 +000072 AccessDevicePort uniPort1 = new AccessDevicePort(new DefaultPort(olt, PortNumber.portNumber(1), true,
73 DefaultAnnotations.builder().set(AnnotationKeys.PORT_NAME, "BBSM00010001-1").build()),
74 AccessDevicePort.Type.UNI);
75 AccessDevicePort uniPort2 = new AccessDevicePort(new DefaultPort(olt, PortNumber.portNumber(2), true,
76 DefaultAnnotations.builder().set(AnnotationKeys.PORT_NAME, "BBSM00010002-1").build()),
77 AccessDevicePort.Type.UNI);
78 AccessDevicePort nniPort = new AccessDevicePort(new DefaultPort(olt, PortNumber.portNumber(65535), true,
79 DefaultAnnotations.builder().set(AnnotationKeys.PORT_NAME, "nni-1048576").build()),
80 AccessDevicePort.Type.NNI);
Andrea Campanellacbbb7952019-11-25 06:38:41 +000081
Tunahan Sezena07fe962021-02-24 08:24:24 +000082 MacAddress macAddress = MacAddress.valueOf("00:00:00:00:0a:0b");
83
Andrea Campanellacbbb7952019-11-25 06:38:41 +000084 UniTagInformation.Builder tagInfoBuilder = new UniTagInformation.Builder();
85 UniTagInformation uniTagInfo = tagInfoBuilder.setUniTagMatch(VlanId.vlanId((short) 35))
86 .setPonCTag(VlanId.vlanId((short) 33))
87 .setPonSTag(VlanId.vlanId((short) 7))
88 .setDsPonCTagPriority(0)
89 .setUsPonSTagPriority(0)
90 .setTechnologyProfileId(64)
91 .setDownstreamBandwidthProfile(dsBpId)
92 .setUpstreamBandwidthProfile(usBpId)
Saurav Dasf62cea82020-08-26 17:43:04 -070093 .setIsDhcpRequired(true)
94 .setIsIgmpRequired(true)
95 .build();
96
Andrea Campanella3a96ce82021-02-09 12:32:42 +010097 UniTagInformation.Builder tagInfoBuilderNoPcp = new UniTagInformation.Builder();
98 UniTagInformation uniTagInfoNoPcp = tagInfoBuilderNoPcp.setUniTagMatch(VlanId.vlanId((short) 35))
99 .setPonCTag(VlanId.vlanId((short) 34))
100 .setPonSTag(VlanId.vlanId((short) 7))
101 .setDsPonCTagPriority(-1)
102 .setUsPonSTagPriority(-1)
103 .setUsPonCTagPriority(-1)
104 .setDsPonSTagPriority(-1)
105 .setTechnologyProfileId(64)
106 .setDownstreamBandwidthProfile(dsBpId)
107 .setUpstreamBandwidthProfile(usBpId)
108 .setIsDhcpRequired(true)
109 .setIsIgmpRequired(true)
110 .build();
111
Saurav Dasf62cea82020-08-26 17:43:04 -0700112 UniTagInformation.Builder tagInfoBuilder2 = new UniTagInformation.Builder();
113 UniTagInformation uniTagInfoNoDhcpNoIgmp = tagInfoBuilder2
114 .setUniTagMatch(VlanId.vlanId((short) 35))
115 .setPonCTag(VlanId.vlanId((short) 33))
116 .setPonSTag(VlanId.vlanId((short) 7))
117 .setDsPonCTagPriority(0)
118 .setUsPonSTagPriority(0)
119 .setTechnologyProfileId(64)
120 .setDownstreamBandwidthProfile(dsBpId)
121 .setUpstreamBandwidthProfile(usBpId)
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000122 .build();
123
124 @Before
125 public void setUp() {
126 oltFlowService = new OltFlowService();
127 oltFlowService.oltMeterService = new MockOltMeterService();
128 oltFlowService.flowObjectiveService = new MockOltFlowObjectiveService();
129 oltFlowService.mastershipService = new MockMastershipService();
130 oltFlowService.sadisService = new MockSadisService();
131 oltFlowService.bpService = oltFlowService.sadisService.getBandwidthProfileService();
132 oltFlowService.appId = appId;
Ilayda Ozdemir90a93622021-02-25 09:40:58 +0000133 oltFlowService.pendingEapolForDevice = Maps.newConcurrentMap();
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000134 }
135
136 @Test
137 public void testDhcpFiltering() {
Tunahan Sezenf0843b92021-04-30 07:13:16 +0000138 System.out.println(uniPort1);
Saurav Dasf62cea82020-08-26 17:43:04 -0700139 oltFlowService.flowObjectiveService.clearQueue();
140 // ensure upstream dhcp traps can be added and removed
Tunahan Sezenf0843b92021-04-30 07:13:16 +0000141 oltFlowService.processDhcpFilteringObjectives(uniPort1,
yasin saplib4b8ee12021-06-13 18:25:20 +0000142 usMeterId, null, uniTagInfo,
Tunahan Sezena07fe962021-02-24 08:24:24 +0000143 true, true, Optional.empty());
Saurav Dasf62cea82020-08-26 17:43:04 -0700144 assert oltFlowService.flowObjectiveService.getPendingFlowObjectives().size() == 1;
Tunahan Sezenf0843b92021-04-30 07:13:16 +0000145 oltFlowService.processDhcpFilteringObjectives(uniPort1,
yasin saplib4b8ee12021-06-13 18:25:20 +0000146 usMeterId, null, uniTagInfo,
Tunahan Sezena07fe962021-02-24 08:24:24 +0000147 false, true, Optional.empty());
Saurav Dasf62cea82020-08-26 17:43:04 -0700148 assert oltFlowService.flowObjectiveService.getPendingFlowObjectives().size() == 2;
Andrea Campanella3a96ce82021-02-09 12:32:42 +0100149
150 // Ensure upstream flow has no pcp unless properly specified.
Tunahan Sezenf0843b92021-04-30 07:13:16 +0000151 oltFlowService.processDhcpFilteringObjectives(uniPort2,
yasin saplib4b8ee12021-06-13 18:25:20 +0000152 usMeterId, null, uniTagInfoNoPcp,
Tunahan Sezena07fe962021-02-24 08:24:24 +0000153 true, true, Optional.empty());
Andrea Campanella3a96ce82021-02-09 12:32:42 +0100154 assert oltFlowService.flowObjectiveService.getPendingFlowObjectives().size() == 3;
155
Saurav Dasf62cea82020-08-26 17:43:04 -0700156 // ensure upstream flows are not added if uniTagInfo is missing dhcp requirement
Tunahan Sezenf0843b92021-04-30 07:13:16 +0000157 oltFlowService.processDhcpFilteringObjectives(uniPort1,
yasin saplib4b8ee12021-06-13 18:25:20 +0000158 usMeterId, null, uniTagInfoNoDhcpNoIgmp,
Tunahan Sezena07fe962021-02-24 08:24:24 +0000159 true, true, Optional.empty());
Andrea Campanella3a96ce82021-02-09 12:32:42 +0100160 assert oltFlowService.flowObjectiveService.getPendingFlowObjectives().size() == 3;
Saurav Dasf62cea82020-08-26 17:43:04 -0700161
162 // ensure downstream traps don't succeed without global config for nni ports
Tunahan Sezenf0843b92021-04-30 07:13:16 +0000163 oltFlowService.processDhcpFilteringObjectives(nniPort,
yasin saplib4b8ee12021-06-13 18:25:20 +0000164 null, null, null,
Tunahan Sezena07fe962021-02-24 08:24:24 +0000165 true, false, Optional.empty());
Tunahan Sezenf0843b92021-04-30 07:13:16 +0000166 oltFlowService.processDhcpFilteringObjectives(nniPort,
yasin saplib4b8ee12021-06-13 18:25:20 +0000167 null, null, null,
Tunahan Sezena07fe962021-02-24 08:24:24 +0000168 false, false, Optional.empty());
Andrea Campanella3a96ce82021-02-09 12:32:42 +0100169 assert oltFlowService.flowObjectiveService.getPendingFlowObjectives().size() == 3;
Saurav Dasf62cea82020-08-26 17:43:04 -0700170 // do global config for nni ports and now it should succeed
171 oltFlowService.enableDhcpOnNni = true;
Tunahan Sezenf0843b92021-04-30 07:13:16 +0000172 oltFlowService.processDhcpFilteringObjectives(nniPort,
yasin saplib4b8ee12021-06-13 18:25:20 +0000173 null, null, null,
Tunahan Sezena07fe962021-02-24 08:24:24 +0000174 true, false, Optional.empty());
Tunahan Sezenf0843b92021-04-30 07:13:16 +0000175 oltFlowService.processDhcpFilteringObjectives(nniPort,
yasin saplib4b8ee12021-06-13 18:25:20 +0000176 null, null, null,
Tunahan Sezena07fe962021-02-24 08:24:24 +0000177 false, false, Optional.empty());
Andrea Campanella3a96ce82021-02-09 12:32:42 +0100178 assert oltFlowService.flowObjectiveService.getPendingFlowObjectives().size() == 5;
Saurav Dasf62cea82020-08-26 17:43:04 -0700179
180 // turn on DHCPv6 and we should get 2 flows
181 oltFlowService.enableDhcpV6 = true;
Tunahan Sezenf0843b92021-04-30 07:13:16 +0000182 oltFlowService.processDhcpFilteringObjectives(uniPort1,
yasin saplib4b8ee12021-06-13 18:25:20 +0000183 usMeterId, null, uniTagInfo,
Tunahan Sezena07fe962021-02-24 08:24:24 +0000184 true, true, Optional.empty());
Andrea Campanella3a96ce82021-02-09 12:32:42 +0100185 assert oltFlowService.flowObjectiveService.getPendingFlowObjectives().size() == 7;
Saurav Dasf62cea82020-08-26 17:43:04 -0700186
187 // turn off DHCPv4 and it's only v6
188 oltFlowService.enableDhcpV4 = false;
Tunahan Sezenf0843b92021-04-30 07:13:16 +0000189 oltFlowService.processDhcpFilteringObjectives(uniPort1,
yasin saplib4b8ee12021-06-13 18:25:20 +0000190 usMeterId, null, uniTagInfo,
Tunahan Sezena07fe962021-02-24 08:24:24 +0000191 true, true, Optional.empty());
Andrea Campanella3a96ce82021-02-09 12:32:42 +0100192 assert oltFlowService.flowObjectiveService.getPendingFlowObjectives().size() == 8;
Saurav Dasf62cea82020-08-26 17:43:04 -0700193
194 // cleanup
195 oltFlowService.flowObjectiveService.clearQueue();
196 oltFlowService.enableDhcpV4 = true;
197 oltFlowService.enableDhcpV6 = false;
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000198 }
199
200 @Test
Gustavo Silva5c492dd2021-02-12 10:21:11 -0300201 public void testPppoedFiltering() {
202 oltFlowService.flowObjectiveService.clearQueue();
203
204 // ensure pppoed traps are not added if global config is off.
205 oltFlowService.enablePppoe = false;
Tunahan Sezenf0843b92021-04-30 07:13:16 +0000206 oltFlowService.processPPPoEDFilteringObjectives(uniPort1,
yasin saplib4b8ee12021-06-13 18:25:20 +0000207 usMeterId, null, uniTagInfo,
Ilayda Ozdemir90a93622021-02-25 09:40:58 +0000208 true, true);
Gustavo Silva5c492dd2021-02-12 10:21:11 -0300209 assert oltFlowService.flowObjectiveService.getPendingFlowObjectives().size() == 0;
210
211 // ensure upstream pppoed traps can be added and removed
212 oltFlowService.enablePppoe = true;
Tunahan Sezenf0843b92021-04-30 07:13:16 +0000213 oltFlowService.processPPPoEDFilteringObjectives(uniPort1,
yasin saplib4b8ee12021-06-13 18:25:20 +0000214 usMeterId, null, uniTagInfo,
Ilayda Ozdemir90a93622021-02-25 09:40:58 +0000215 true, true);
Gustavo Silva5c492dd2021-02-12 10:21:11 -0300216 assert oltFlowService.flowObjectiveService.getPendingFlowObjectives().size() == 1;
Tunahan Sezenf0843b92021-04-30 07:13:16 +0000217 oltFlowService.processPPPoEDFilteringObjectives(uniPort1,
yasin saplib4b8ee12021-06-13 18:25:20 +0000218 usMeterId, null, uniTagInfo,
Ilayda Ozdemir90a93622021-02-25 09:40:58 +0000219 false, true);
Gustavo Silva5c492dd2021-02-12 10:21:11 -0300220 assert oltFlowService.flowObjectiveService.getPendingFlowObjectives().size() == 2;
221
222 // ensure downstream pppoed traps can be added and removed
Tunahan Sezenf0843b92021-04-30 07:13:16 +0000223 oltFlowService.processPPPoEDFilteringObjectives(nniPort,
yasin saplib4b8ee12021-06-13 18:25:20 +0000224 null, null, null,
Ilayda Ozdemir90a93622021-02-25 09:40:58 +0000225 true, false);
Gustavo Silva5c492dd2021-02-12 10:21:11 -0300226 assert oltFlowService.flowObjectiveService.getPendingFlowObjectives().size() == 3;
Tunahan Sezenf0843b92021-04-30 07:13:16 +0000227 oltFlowService.processPPPoEDFilteringObjectives(nniPort,
yasin saplib4b8ee12021-06-13 18:25:20 +0000228 null, null, null,
Ilayda Ozdemir90a93622021-02-25 09:40:58 +0000229 false, false);
Gustavo Silva5c492dd2021-02-12 10:21:11 -0300230 assert oltFlowService.flowObjectiveService.getPendingFlowObjectives().size() == 4;
231
232 // cleanup
233 oltFlowService.flowObjectiveService.clearQueue();
234 }
235
236 @Test
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000237 public void testIgmpFiltering() {
Saurav Dasf62cea82020-08-26 17:43:04 -0700238 oltFlowService.flowObjectiveService.clearQueue();
239
240 // ensure igmp flows can be added and removed
Tunahan Sezenf0843b92021-04-30 07:13:16 +0000241 oltFlowService.processIgmpFilteringObjectives(uniPort1,
yasin saplib4b8ee12021-06-13 18:25:20 +0000242 usMeterId, null, uniTagInfo,
Ilayda Ozdemir90a93622021-02-25 09:40:58 +0000243 true, true);
Saurav Dasf62cea82020-08-26 17:43:04 -0700244 assert oltFlowService.flowObjectiveService.getPendingFlowObjectives().size() == 1;
Tunahan Sezenf0843b92021-04-30 07:13:16 +0000245 oltFlowService.processIgmpFilteringObjectives(uniPort1, usMeterId,
yasin saplib4b8ee12021-06-13 18:25:20 +0000246 null, uniTagInfo,
Ilayda Ozdemir90a93622021-02-25 09:40:58 +0000247 false, true);
Saurav Dasf62cea82020-08-26 17:43:04 -0700248 assert oltFlowService.flowObjectiveService.getPendingFlowObjectives().size() == 2;
249
250 // ensure igmp flow is not added if uniTag has no igmp requirement
Tunahan Sezenf0843b92021-04-30 07:13:16 +0000251 oltFlowService.processIgmpFilteringObjectives(uniPort1,
yasin saplib4b8ee12021-06-13 18:25:20 +0000252 usMeterId, null, uniTagInfoNoDhcpNoIgmp,
Ilayda Ozdemir90a93622021-02-25 09:40:58 +0000253 true, true);
Saurav Dasf62cea82020-08-26 17:43:04 -0700254 assert oltFlowService.flowObjectiveService.getPendingFlowObjectives().size() == 2;
255
256 //ensure igmp flow on NNI fails without global setting
Tunahan Sezenf0843b92021-04-30 07:13:16 +0000257 oltFlowService.processIgmpFilteringObjectives(nniPort,
yasin saplib4b8ee12021-06-13 18:25:20 +0000258 null, null, null,
Ilayda Ozdemir90a93622021-02-25 09:40:58 +0000259 true, false);
Saurav Dasf62cea82020-08-26 17:43:04 -0700260 assert oltFlowService.flowObjectiveService.getPendingFlowObjectives().size() == 2;
261
262 // igmp trap on NNI should succeed with global config
263 oltFlowService.enableIgmpOnNni = true;
Tunahan Sezenf0843b92021-04-30 07:13:16 +0000264 oltFlowService.processIgmpFilteringObjectives(nniPort,
yasin saplib4b8ee12021-06-13 18:25:20 +0000265 null, null, null,
Ilayda Ozdemir90a93622021-02-25 09:40:58 +0000266 true, false);
Saurav Dasf62cea82020-08-26 17:43:04 -0700267 assert oltFlowService.flowObjectiveService.getPendingFlowObjectives().size() == 3;
268 // cleanup
269 oltFlowService.flowObjectiveService.clearQueue();
270
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000271 }
272
273 @Test
274 public void testEapolFiltering() {
275 addBandwidthProfile(uniTagInfo.getUpstreamBandwidthProfile());
276 oltFlowService.enableEapol = true;
277
278 //will install
Tunahan Sezenf0843b92021-04-30 07:13:16 +0000279 oltFlowService.processEapolFilteringObjectives(uniPort1,
yasin saplib4b8ee12021-06-13 18:25:20 +0000280 uniTagInfo.getUpstreamBandwidthProfile(), Optional.empty(), new CompletableFuture<>(),
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000281 uniTagInfo.getUniTagMatch(), true);
282
283 //bp profile doesn't exist
Tunahan Sezenf0843b92021-04-30 07:13:16 +0000284 oltFlowService.processEapolFilteringObjectives(uniPort1,
yasin saplib4b8ee12021-06-13 18:25:20 +0000285 uniTagInfo.getDownstreamBandwidthProfile(), Optional.empty(), new CompletableFuture<>(),
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000286 uniTagInfo.getUniTagMatch(), true);
287 }
288
289 @Test
290 public void testLldpFiltering() {
Tunahan Sezenf0843b92021-04-30 07:13:16 +0000291 oltFlowService.processLldpFilteringObjective(nniPort, true);
292 oltFlowService.processLldpFilteringObjective(nniPort, false);
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000293 }
294
295 @Test
296 public void testNniFiltering() {
Saurav Dasf62cea82020-08-26 17:43:04 -0700297 oltFlowService.flowObjectiveService.clearQueue();
298 oltFlowService.enableDhcpOnNni = true;
299 oltFlowService.enableIgmpOnNni = true;
Tunahan Sezenf0843b92021-04-30 07:13:16 +0000300 oltFlowService.processNniFilteringObjectives(nniPort, true);
Saurav Dasf62cea82020-08-26 17:43:04 -0700301 assert oltFlowService.flowObjectiveService.getPendingFlowObjectives()
302 .size() == 3;
Tunahan Sezenf0843b92021-04-30 07:13:16 +0000303 oltFlowService.processNniFilteringObjectives(nniPort, false);
Saurav Dasf62cea82020-08-26 17:43:04 -0700304 assert oltFlowService.flowObjectiveService.getPendingFlowObjectives()
305 .size() == 6;
306 oltFlowService.flowObjectiveService.clearQueue();
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000307 }
308
309 @Test
310 public void testUpBuilder() {
311 ForwardingObjective objective =
yasin saplib4b8ee12021-06-13 18:25:20 +0000312 oltFlowService.createUpBuilder(nniPort, uniPort1, usMeterId, usMeterId, uniTagInfo).add();
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000313 checkObjective(objective, true);
314 }
315
316 @Test
317 public void testDownBuilder() {
318 ForwardingObjective objective =
yasin saplib4b8ee12021-06-13 18:25:20 +0000319 oltFlowService.createDownBuilder(nniPort, uniPort1, dsMeterId, dsMeterId, uniTagInfo,
Tunahan Sezena07fe962021-02-24 08:24:24 +0000320 Optional.of(macAddress)).remove();
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000321 checkObjective(objective, false);
322 }
323
324 private void checkObjective(ForwardingObjective fwd, boolean upstream) {
325 TrafficTreatment treatment = fwd.treatment();
326
327 //check instructions
328 Set<Instructions.MeterInstruction> meters = treatment.meters();
329 assert !meters.isEmpty();
330
331 Instructions.MetadataInstruction writeMetadata = treatment.writeMetadata();
332 assert writeMetadata != null;
333
334 List<Instruction> immediateInstructions = treatment.immediate();
335 Optional<Instruction> vlanInstruction = immediateInstructions.stream()
336 .filter(i -> i.type() == Instruction.Type.L2MODIFICATION)
337 .filter(i -> ((L2ModificationInstruction) i).subtype() ==
338 L2ModificationInstruction.L2SubType.VLAN_PUSH ||
339 ((L2ModificationInstruction) i).subtype() ==
340 L2ModificationInstruction.L2SubType.VLAN_POP)
341 .findAny();
342
343 assert vlanInstruction.isPresent();
344
345 //check match criteria
346 TrafficSelector selector = fwd.selector();
347 assert selector.getCriterion(Criterion.Type.IN_PORT) != null;
348 assert selector.getCriterion(Criterion.Type.VLAN_VID) != null;
349
350 if (!upstream) {
Ilayda Ozdemir90a93622021-02-25 09:40:58 +0000351 assert selector.getCriterion(Criterion.Type.METADATA) != null;
Tunahan Sezena07fe962021-02-24 08:24:24 +0000352 assert selector.getCriterion(Criterion.Type.ETH_DST) != null;
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000353 }
354 }
355
356 private class MockOltMeterService implements org.opencord.olt.internalapi.AccessDeviceMeterService {
357 @Override
358 public ImmutableMap<String, Collection<MeterKey>> getBpMeterMappings() {
359 return null;
360 }
361
362 @Override
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000363 public MeterId getMeterIdFromBpMapping(DeviceId deviceId, String bandwidthProfile) {
364 return null;
365 }
366
367
368 @Override
369 public ImmutableSet<MeterKey> getProgMeters() {
370 return null;
371 }
372
373 @Override
374 public MeterId createMeter(DeviceId deviceId, BandwidthProfileInformation bpInfo,
375 CompletableFuture<Object> meterFuture) {
376 return usMeterId;
377 }
Jonathan Hart4f178fa2020-02-03 10:46:01 -0800378
379 @Override
Andrea Campanella600d2e22020-06-22 11:00:31 +0200380 public void removeFromPendingMeters(DeviceId deviceId, BandwidthProfileInformation bwpInfo) {
381
Andrea Campanella3ce4d282020-06-09 13:46:58 +0200382 }
383
384 @Override
Andrea Campanellad1e26642020-10-23 12:08:32 +0200385 public boolean checkAndAddPendingMeter(DeviceId deviceId, BandwidthProfileInformation bwpInfo) {
Andrea Campanella3ce4d282020-06-09 13:46:58 +0200386 return false;
387 }
388
Andrea Campanella600d2e22020-06-22 11:00:31 +0200389
Andrea Campanella3ce4d282020-06-09 13:46:58 +0200390 @Override
Jonathan Hart4f178fa2020-02-03 10:46:01 -0800391 public void clearMeters(DeviceId deviceId) {
392 }
Andrea Campanella600d2e22020-06-22 11:00:31 +0200393
394 @Override
395 public void clearDeviceState(DeviceId deviceId) {
396
397 }
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000398 }
399
400 private class MockOltFlowObjectiveService implements org.onosproject.net.flowobjective.FlowObjectiveService {
Saurav Dasf62cea82020-08-26 17:43:04 -0700401 List<String> flowObjectives = new ArrayList<>();
402
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000403 @Override
404 public void filter(DeviceId deviceId, FilteringObjective filteringObjective) {
Saurav Dasf62cea82020-08-26 17:43:04 -0700405 flowObjectives.add(filteringObjective.toString());
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000406 EthTypeCriterion ethType = (EthTypeCriterion)
407 filterForCriterion(filteringObjective.conditions(), Criterion.Type.ETH_TYPE);
408
409 Instructions.MeterInstruction meter = filteringObjective.meta().metered();
410 Instruction writeMetadata = filteringObjective.meta().writeMetadata();
411 VlanIdCriterion vlanIdCriterion = (VlanIdCriterion)
412 filterForCriterion(filteringObjective.conditions(), Criterion.Type.VLAN_VID);
413 PortCriterion portCriterion = (PortCriterion) filteringObjective.key();
414
Andrea Campanella3a96ce82021-02-09 12:32:42 +0100415 filteringObjective.meta().allInstructions().forEach(instruction -> {
416 if (instruction.type().equals(Instruction.Type.L2MODIFICATION)) {
417 L2ModificationInstruction l2Instruction = (L2ModificationInstruction) instruction;
418 if (l2Instruction.subtype().equals(L2ModificationInstruction.L2SubType.VLAN_PCP)) {
419 //this, given the uniTagInfo we provide, should not be present
420 assert false;
421 }
422 }
423 });
424
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000425
426 if (ethType.ethType().equals(EthType.EtherType.LLDP.ethType()) ||
Tunahan Sezenf0843b92021-04-30 07:13:16 +0000427 portCriterion.port().equals(nniPort.number())) {
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000428 assert meter == null;
429 assert writeMetadata == null;
430 assert vlanIdCriterion == null;
431 } else {
432 assert meter.meterId().equals(usMeterId) || meter.meterId().equals(dsMeterId);
433 assert writeMetadata != null;
Andrea Campanella3a96ce82021-02-09 12:32:42 +0100434 assert vlanIdCriterion == null || vlanIdCriterion.vlanId() == uniTagInfo.getUniTagMatch()
435 || vlanIdCriterion.vlanId() == uniTagInfoNoPcp.getUniTagMatch();
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000436 }
437
438 }
439
440 @Override
441 public void forward(DeviceId deviceId, ForwardingObjective forwardingObjective) {
442
443 }
444
445 @Override
446 public void next(DeviceId deviceId, NextObjective nextObjective) {
447
448 }
449
450 @Override
451 public int allocateNextId() {
452 return 0;
453 }
454
455 @Override
456 public void initPolicy(String s) {
457
458 }
459
460 @Override
461 public void apply(DeviceId deviceId, Objective objective) {
462
463 }
464
465 @Override
466 public Map<Pair<Integer, DeviceId>, List<String>> getNextMappingsChain() {
467 return null;
468 }
469
470 @Override
471 public List<String> getNextMappings() {
472 return null;
473 }
474
475 @Override
476 public List<String> getPendingFlowObjectives() {
Saurav Dasf62cea82020-08-26 17:43:04 -0700477 return ImmutableList.copyOf(flowObjectives);
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000478 }
479
480 @Override
481 public ListMultimap<FilteringObjQueueKey, Objective> getFilteringObjQueue() {
482 return null;
483 }
484
485 @Override
486 public ListMultimap<ForwardingObjQueueKey, Objective> getForwardingObjQueue() {
487 return null;
488 }
489
490 @Override
491 public ListMultimap<NextObjQueueKey, Objective> getNextObjQueue() {
492 return null;
493 }
494
495 @Override
496 public Map<FilteringObjQueueKey, Objective> getFilteringObjQueueHead() {
497 return null;
498 }
499
500 @Override
501 public Map<ForwardingObjQueueKey, Objective> getForwardingObjQueueHead() {
502 return null;
503 }
504
505 @Override
506 public Map<NextObjQueueKey, Objective> getNextObjQueueHead() {
507 return null;
508 }
509
510 @Override
511 public void clearQueue() {
Saurav Dasf62cea82020-08-26 17:43:04 -0700512 flowObjectives.clear();
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000513 }
514
515 private Criterion filterForCriterion(Collection<Criterion> criteria, Criterion.Type type) {
516 return criteria.stream()
517 .filter(c -> c.type().equals(type))
518 .limit(1)
519 .findFirst().orElse(null);
520 }
521 }
522
523 private class MockMastershipService implements org.onosproject.mastership.MastershipService {
524 @Override
525 public MastershipRole getLocalRole(DeviceId deviceId) {
526 return null;
527 }
528
529 @Override
530 public boolean isLocalMaster(DeviceId deviceId) {
531 return true;
532 }
533
534 @Override
535 public CompletableFuture<MastershipRole> requestRoleFor(DeviceId deviceId) {
536 return null;
537 }
538
539 @Override
540 public CompletableFuture<Void> relinquishMastership(DeviceId deviceId) {
541 return null;
542 }
543
544 @Override
545 public NodeId getMasterFor(DeviceId deviceId) {
546 return null;
547 }
548
549 @Override
550 public RoleInfo getNodesFor(DeviceId deviceId) {
551 return null;
552 }
553
554 @Override
555 public MastershipInfo getMastershipFor(DeviceId deviceId) {
556 return null;
557 }
558
559 @Override
560 public Set<DeviceId> getDevicesOf(NodeId nodeId) {
561 return null;
562 }
563
564 @Override
565 public void addListener(MastershipListener mastershipListener) {
566
567 }
568
569 @Override
570 public void removeListener(MastershipListener mastershipListener) {
571
572 }
573 }
574}