Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1 | /* |
| 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 | */ |
| 16 | package org.opencord.olt.impl; |
| 17 | |
Saurav Das | f62cea8 | 2020-08-26 17:43:04 -0700 | [diff] [blame] | 18 | import java.util.ArrayList; |
| 19 | import java.util.Collection; |
| 20 | import java.util.List; |
| 21 | import java.util.Map; |
| 22 | import java.util.Optional; |
| 23 | import java.util.Set; |
| 24 | import java.util.concurrent.CompletableFuture; |
| 25 | |
Ilayda Ozdemir | 90a9362 | 2021-02-25 09:40:58 +0000 | [diff] [blame] | 26 | import com.google.common.collect.Maps; |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 27 | import org.apache.commons.lang3.tuple.Pair; |
| 28 | import org.junit.Before; |
| 29 | import org.junit.Test; |
| 30 | import org.onlab.packet.EthType; |
| 31 | import org.onlab.packet.VlanId; |
| 32 | import org.onosproject.cluster.NodeId; |
| 33 | import org.onosproject.cluster.RoleInfo; |
| 34 | import org.onosproject.mastership.MastershipInfo; |
| 35 | import org.onosproject.mastership.MastershipListener; |
| 36 | import org.onosproject.net.DeviceId; |
| 37 | import org.onosproject.net.MastershipRole; |
| 38 | import org.onosproject.net.PortNumber; |
| 39 | import org.onosproject.net.flow.TrafficSelector; |
| 40 | import org.onosproject.net.flow.TrafficTreatment; |
| 41 | import org.onosproject.net.flow.criteria.Criterion; |
| 42 | import org.onosproject.net.flow.criteria.EthTypeCriterion; |
| 43 | import org.onosproject.net.flow.criteria.PortCriterion; |
| 44 | import org.onosproject.net.flow.criteria.VlanIdCriterion; |
| 45 | import org.onosproject.net.flow.instructions.Instruction; |
| 46 | import org.onosproject.net.flow.instructions.Instructions; |
| 47 | import org.onosproject.net.flow.instructions.L2ModificationInstruction; |
| 48 | import org.onosproject.net.flowobjective.FilteringObjQueueKey; |
| 49 | import org.onosproject.net.flowobjective.FilteringObjective; |
| 50 | import org.onosproject.net.flowobjective.ForwardingObjQueueKey; |
| 51 | import org.onosproject.net.flowobjective.ForwardingObjective; |
| 52 | import org.onosproject.net.flowobjective.NextObjQueueKey; |
| 53 | import org.onosproject.net.flowobjective.NextObjective; |
| 54 | import org.onosproject.net.flowobjective.Objective; |
| 55 | import org.onosproject.net.meter.MeterId; |
| 56 | import org.onosproject.net.meter.MeterKey; |
| 57 | import org.opencord.sadis.BandwidthProfileInformation; |
| 58 | import org.opencord.sadis.UniTagInformation; |
| 59 | |
Saurav Das | f62cea8 | 2020-08-26 17:43:04 -0700 | [diff] [blame] | 60 | import com.google.common.collect.ImmutableList; |
| 61 | import com.google.common.collect.ImmutableMap; |
| 62 | import com.google.common.collect.ImmutableSet; |
| 63 | import com.google.common.collect.ListMultimap; |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 64 | |
| 65 | public class OltFlowTest extends TestBase { |
| 66 | private OltFlowService oltFlowService; |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 67 | PortNumber uniPortNumber = PortNumber.portNumber(1); |
Andrea Campanella | 3a96ce8 | 2021-02-09 12:32:42 +0100 | [diff] [blame] | 68 | PortNumber uniPortNumber2 = PortNumber.portNumber(2); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 69 | 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 Das | f62cea8 | 2020-08-26 17:43:04 -0700 | [diff] [blame] | 80 | .setIsDhcpRequired(true) |
| 81 | .setIsIgmpRequired(true) |
| 82 | .build(); |
| 83 | |
Andrea Campanella | 3a96ce8 | 2021-02-09 12:32:42 +0100 | [diff] [blame] | 84 | 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 Das | f62cea8 | 2020-08-26 17:43:04 -0700 | [diff] [blame] | 99 | 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 Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 109 | .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 Ozdemir | 90a9362 | 2021-02-25 09:40:58 +0000 | [diff] [blame] | 120 | oltFlowService.pendingEapolForDevice = Maps.newConcurrentMap(); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 121 | } |
| 122 | |
| 123 | @Test |
| 124 | public void testDhcpFiltering() { |
Saurav Das | f62cea8 | 2020-08-26 17:43:04 -0700 | [diff] [blame] | 125 | oltFlowService.flowObjectiveService.clearQueue(); |
| 126 | // ensure upstream dhcp traps can be added and removed |
| 127 | oltFlowService.processDhcpFilteringObjectives(DEVICE_ID_1, uniPortNumber, |
Ilayda Ozdemir | 90a9362 | 2021-02-25 09:40:58 +0000 | [diff] [blame] | 128 | usMeterId, uniTagInfo, |
| 129 | true, true); |
Saurav Das | f62cea8 | 2020-08-26 17:43:04 -0700 | [diff] [blame] | 130 | assert oltFlowService.flowObjectiveService.getPendingFlowObjectives().size() == 1; |
| 131 | oltFlowService.processDhcpFilteringObjectives(DEVICE_ID_1, uniPortNumber, |
Ilayda Ozdemir | 90a9362 | 2021-02-25 09:40:58 +0000 | [diff] [blame] | 132 | usMeterId, uniTagInfo, |
| 133 | false, true); |
Saurav Das | f62cea8 | 2020-08-26 17:43:04 -0700 | [diff] [blame] | 134 | assert oltFlowService.flowObjectiveService.getPendingFlowObjectives().size() == 2; |
Andrea Campanella | 3a96ce8 | 2021-02-09 12:32:42 +0100 | [diff] [blame] | 135 | |
| 136 | // Ensure upstream flow has no pcp unless properly specified. |
| 137 | oltFlowService.processDhcpFilteringObjectives(DEVICE_ID_1, uniPortNumber2, |
Ilayda Ozdemir | 90a9362 | 2021-02-25 09:40:58 +0000 | [diff] [blame] | 138 | usMeterId, uniTagInfoNoPcp, |
| 139 | true, true); |
Andrea Campanella | 3a96ce8 | 2021-02-09 12:32:42 +0100 | [diff] [blame] | 140 | assert oltFlowService.flowObjectiveService.getPendingFlowObjectives().size() == 3; |
| 141 | |
Saurav Das | f62cea8 | 2020-08-26 17:43:04 -0700 | [diff] [blame] | 142 | // ensure upstream flows are not added if uniTagInfo is missing dhcp requirement |
| 143 | oltFlowService.processDhcpFilteringObjectives(DEVICE_ID_1, uniPortNumber, |
Ilayda Ozdemir | 90a9362 | 2021-02-25 09:40:58 +0000 | [diff] [blame] | 144 | usMeterId, uniTagInfoNoDhcpNoIgmp, |
| 145 | true, true); |
Andrea Campanella | 3a96ce8 | 2021-02-09 12:32:42 +0100 | [diff] [blame] | 146 | assert oltFlowService.flowObjectiveService.getPendingFlowObjectives().size() == 3; |
Saurav Das | f62cea8 | 2020-08-26 17:43:04 -0700 | [diff] [blame] | 147 | |
| 148 | // ensure downstream traps don't succeed without global config for nni ports |
| 149 | oltFlowService.processDhcpFilteringObjectives(DEVICE_ID_1, nniPortNumber, |
Ilayda Ozdemir | 90a9362 | 2021-02-25 09:40:58 +0000 | [diff] [blame] | 150 | null, null, |
| 151 | true, false); |
Saurav Das | f62cea8 | 2020-08-26 17:43:04 -0700 | [diff] [blame] | 152 | oltFlowService.processDhcpFilteringObjectives(DEVICE_ID_1, nniPortNumber, |
Ilayda Ozdemir | 90a9362 | 2021-02-25 09:40:58 +0000 | [diff] [blame] | 153 | null, null, |
| 154 | false, false); |
Andrea Campanella | 3a96ce8 | 2021-02-09 12:32:42 +0100 | [diff] [blame] | 155 | assert oltFlowService.flowObjectiveService.getPendingFlowObjectives().size() == 3; |
Saurav Das | f62cea8 | 2020-08-26 17:43:04 -0700 | [diff] [blame] | 156 | // do global config for nni ports and now it should succeed |
| 157 | oltFlowService.enableDhcpOnNni = true; |
| 158 | oltFlowService.processDhcpFilteringObjectives(DEVICE_ID_1, nniPortNumber, |
Ilayda Ozdemir | 90a9362 | 2021-02-25 09:40:58 +0000 | [diff] [blame] | 159 | null, null, |
| 160 | true, false); |
Saurav Das | f62cea8 | 2020-08-26 17:43:04 -0700 | [diff] [blame] | 161 | oltFlowService.processDhcpFilteringObjectives(DEVICE_ID_1, nniPortNumber, |
Ilayda Ozdemir | 90a9362 | 2021-02-25 09:40:58 +0000 | [diff] [blame] | 162 | null, null, |
| 163 | false, false); |
Andrea Campanella | 3a96ce8 | 2021-02-09 12:32:42 +0100 | [diff] [blame] | 164 | assert oltFlowService.flowObjectiveService.getPendingFlowObjectives().size() == 5; |
Saurav Das | f62cea8 | 2020-08-26 17:43:04 -0700 | [diff] [blame] | 165 | |
| 166 | // turn on DHCPv6 and we should get 2 flows |
| 167 | oltFlowService.enableDhcpV6 = true; |
| 168 | oltFlowService.processDhcpFilteringObjectives(DEVICE_ID_1, uniPortNumber, |
Ilayda Ozdemir | 90a9362 | 2021-02-25 09:40:58 +0000 | [diff] [blame] | 169 | usMeterId, uniTagInfo, |
| 170 | true, true); |
Andrea Campanella | 3a96ce8 | 2021-02-09 12:32:42 +0100 | [diff] [blame] | 171 | assert oltFlowService.flowObjectiveService.getPendingFlowObjectives().size() == 7; |
Saurav Das | f62cea8 | 2020-08-26 17:43:04 -0700 | [diff] [blame] | 172 | |
| 173 | // turn off DHCPv4 and it's only v6 |
| 174 | oltFlowService.enableDhcpV4 = false; |
| 175 | oltFlowService.processDhcpFilteringObjectives(DEVICE_ID_1, uniPortNumber, |
Ilayda Ozdemir | 90a9362 | 2021-02-25 09:40:58 +0000 | [diff] [blame] | 176 | usMeterId, uniTagInfo, |
| 177 | true, true); |
Andrea Campanella | 3a96ce8 | 2021-02-09 12:32:42 +0100 | [diff] [blame] | 178 | assert oltFlowService.flowObjectiveService.getPendingFlowObjectives().size() == 8; |
Saurav Das | f62cea8 | 2020-08-26 17:43:04 -0700 | [diff] [blame] | 179 | |
| 180 | // cleanup |
| 181 | oltFlowService.flowObjectiveService.clearQueue(); |
| 182 | oltFlowService.enableDhcpV4 = true; |
| 183 | oltFlowService.enableDhcpV6 = false; |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 184 | } |
| 185 | |
| 186 | @Test |
Gustavo Silva | 5c492dd | 2021-02-12 10:21:11 -0300 | [diff] [blame] | 187 | 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 Ozdemir | 90a9362 | 2021-02-25 09:40:58 +0000 | [diff] [blame] | 193 | usMeterId, uniTagInfo, |
| 194 | true, true); |
Gustavo Silva | 5c492dd | 2021-02-12 10:21:11 -0300 | [diff] [blame] | 195 | 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 Ozdemir | 90a9362 | 2021-02-25 09:40:58 +0000 | [diff] [blame] | 200 | usMeterId, uniTagInfo, |
| 201 | true, true); |
Gustavo Silva | 5c492dd | 2021-02-12 10:21:11 -0300 | [diff] [blame] | 202 | assert oltFlowService.flowObjectiveService.getPendingFlowObjectives().size() == 1; |
| 203 | oltFlowService.processPPPoEDFilteringObjectives(DEVICE_ID_1, uniPortNumber, |
Ilayda Ozdemir | 90a9362 | 2021-02-25 09:40:58 +0000 | [diff] [blame] | 204 | usMeterId, uniTagInfo, |
| 205 | false, true); |
Gustavo Silva | 5c492dd | 2021-02-12 10:21:11 -0300 | [diff] [blame] | 206 | 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 Ozdemir | 90a9362 | 2021-02-25 09:40:58 +0000 | [diff] [blame] | 210 | null, null, |
| 211 | true, false); |
Gustavo Silva | 5c492dd | 2021-02-12 10:21:11 -0300 | [diff] [blame] | 212 | assert oltFlowService.flowObjectiveService.getPendingFlowObjectives().size() == 3; |
| 213 | oltFlowService.processPPPoEDFilteringObjectives(DEVICE_ID_1, nniPortNumber, |
Ilayda Ozdemir | 90a9362 | 2021-02-25 09:40:58 +0000 | [diff] [blame] | 214 | null, null, |
| 215 | false, false); |
Gustavo Silva | 5c492dd | 2021-02-12 10:21:11 -0300 | [diff] [blame] | 216 | assert oltFlowService.flowObjectiveService.getPendingFlowObjectives().size() == 4; |
| 217 | |
| 218 | // cleanup |
| 219 | oltFlowService.flowObjectiveService.clearQueue(); |
| 220 | } |
| 221 | |
| 222 | @Test |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 223 | public void testIgmpFiltering() { |
Saurav Das | f62cea8 | 2020-08-26 17:43:04 -0700 | [diff] [blame] | 224 | oltFlowService.flowObjectiveService.clearQueue(); |
| 225 | |
| 226 | // ensure igmp flows can be added and removed |
| 227 | oltFlowService.processIgmpFilteringObjectives(DEVICE_ID_1, uniPortNumber, |
Ilayda Ozdemir | 90a9362 | 2021-02-25 09:40:58 +0000 | [diff] [blame] | 228 | usMeterId, uniTagInfo, |
| 229 | true, true); |
Saurav Das | f62cea8 | 2020-08-26 17:43:04 -0700 | [diff] [blame] | 230 | assert oltFlowService.flowObjectiveService.getPendingFlowObjectives().size() == 1; |
| 231 | oltFlowService.processIgmpFilteringObjectives(DEVICE_ID_1, uniPortNumber, usMeterId, |
Ilayda Ozdemir | 90a9362 | 2021-02-25 09:40:58 +0000 | [diff] [blame] | 232 | uniTagInfo, |
| 233 | false, true); |
Saurav Das | f62cea8 | 2020-08-26 17:43:04 -0700 | [diff] [blame] | 234 | 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 Ozdemir | 90a9362 | 2021-02-25 09:40:58 +0000 | [diff] [blame] | 238 | usMeterId, uniTagInfoNoDhcpNoIgmp, |
| 239 | true, true); |
Saurav Das | f62cea8 | 2020-08-26 17:43:04 -0700 | [diff] [blame] | 240 | 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 Ozdemir | 90a9362 | 2021-02-25 09:40:58 +0000 | [diff] [blame] | 244 | null, null, |
| 245 | true, false); |
Saurav Das | f62cea8 | 2020-08-26 17:43:04 -0700 | [diff] [blame] | 246 | 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 Ozdemir | 90a9362 | 2021-02-25 09:40:58 +0000 | [diff] [blame] | 251 | null, null, |
| 252 | true, false); |
Saurav Das | f62cea8 | 2020-08-26 17:43:04 -0700 | [diff] [blame] | 253 | assert oltFlowService.flowObjectiveService.getPendingFlowObjectives().size() == 3; |
| 254 | // cleanup |
| 255 | oltFlowService.flowObjectiveService.clearQueue(); |
| 256 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 257 | } |
| 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 Das | f62cea8 | 2020-08-26 17:43:04 -0700 | [diff] [blame] | 283 | oltFlowService.flowObjectiveService.clearQueue(); |
| 284 | oltFlowService.enableDhcpOnNni = true; |
| 285 | oltFlowService.enableIgmpOnNni = true; |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 286 | oltFlowService.processNniFilteringObjectives(DEVICE_ID_1, nniPortNumber, true); |
Saurav Das | f62cea8 | 2020-08-26 17:43:04 -0700 | [diff] [blame] | 287 | assert oltFlowService.flowObjectiveService.getPendingFlowObjectives() |
| 288 | .size() == 3; |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 289 | oltFlowService.processNniFilteringObjectives(DEVICE_ID_1, nniPortNumber, false); |
Saurav Das | f62cea8 | 2020-08-26 17:43:04 -0700 | [diff] [blame] | 290 | assert oltFlowService.flowObjectiveService.getPendingFlowObjectives() |
| 291 | .size() == 6; |
| 292 | oltFlowService.flowObjectiveService.clearQueue(); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 293 | } |
| 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 Ozdemir | 90a9362 | 2021-02-25 09:40:58 +0000 | [diff] [blame] | 336 | assert selector.getCriterion(Criterion.Type.METADATA) != null; |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 337 | } |
| 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 Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 347 | 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 Hart | 4f178fa | 2020-02-03 10:46:01 -0800 | [diff] [blame] | 362 | |
| 363 | @Override |
Andrea Campanella | 600d2e2 | 2020-06-22 11:00:31 +0200 | [diff] [blame] | 364 | public void removeFromPendingMeters(DeviceId deviceId, BandwidthProfileInformation bwpInfo) { |
| 365 | |
Andrea Campanella | 3ce4d28 | 2020-06-09 13:46:58 +0200 | [diff] [blame] | 366 | } |
| 367 | |
| 368 | @Override |
Andrea Campanella | d1e2664 | 2020-10-23 12:08:32 +0200 | [diff] [blame] | 369 | public boolean checkAndAddPendingMeter(DeviceId deviceId, BandwidthProfileInformation bwpInfo) { |
Andrea Campanella | 3ce4d28 | 2020-06-09 13:46:58 +0200 | [diff] [blame] | 370 | return false; |
| 371 | } |
| 372 | |
Andrea Campanella | 600d2e2 | 2020-06-22 11:00:31 +0200 | [diff] [blame] | 373 | |
Andrea Campanella | 3ce4d28 | 2020-06-09 13:46:58 +0200 | [diff] [blame] | 374 | @Override |
Jonathan Hart | 4f178fa | 2020-02-03 10:46:01 -0800 | [diff] [blame] | 375 | public void clearMeters(DeviceId deviceId) { |
| 376 | } |
Andrea Campanella | 600d2e2 | 2020-06-22 11:00:31 +0200 | [diff] [blame] | 377 | |
| 378 | @Override |
| 379 | public void clearDeviceState(DeviceId deviceId) { |
| 380 | |
| 381 | } |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 382 | } |
| 383 | |
| 384 | private class MockOltFlowObjectiveService implements org.onosproject.net.flowobjective.FlowObjectiveService { |
Saurav Das | f62cea8 | 2020-08-26 17:43:04 -0700 | [diff] [blame] | 385 | List<String> flowObjectives = new ArrayList<>(); |
| 386 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 387 | @Override |
| 388 | public void filter(DeviceId deviceId, FilteringObjective filteringObjective) { |
Saurav Das | f62cea8 | 2020-08-26 17:43:04 -0700 | [diff] [blame] | 389 | flowObjectives.add(filteringObjective.toString()); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 390 | 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 Campanella | 3a96ce8 | 2021-02-09 12:32:42 +0100 | [diff] [blame] | 399 | 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 Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 409 | |
| 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 Campanella | 3a96ce8 | 2021-02-09 12:32:42 +0100 | [diff] [blame] | 418 | assert vlanIdCriterion == null || vlanIdCriterion.vlanId() == uniTagInfo.getUniTagMatch() |
| 419 | || vlanIdCriterion.vlanId() == uniTagInfoNoPcp.getUniTagMatch(); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 420 | } |
| 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 Das | f62cea8 | 2020-08-26 17:43:04 -0700 | [diff] [blame] | 461 | return ImmutableList.copyOf(flowObjectives); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 462 | } |
| 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 Das | f62cea8 | 2020-08-26 17:43:04 -0700 | [diff] [blame] | 496 | flowObjectives.clear(); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 497 | } |
| 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 | } |