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; |
Tunahan Sezen | a07fe96 | 2021-02-24 08:24:24 +0000 | [diff] [blame^] | 31 | import org.onlab.packet.MacAddress; |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 32 | import org.onlab.packet.VlanId; |
| 33 | import org.onosproject.cluster.NodeId; |
| 34 | import org.onosproject.cluster.RoleInfo; |
| 35 | import org.onosproject.mastership.MastershipInfo; |
| 36 | import org.onosproject.mastership.MastershipListener; |
| 37 | import org.onosproject.net.DeviceId; |
| 38 | import org.onosproject.net.MastershipRole; |
| 39 | import org.onosproject.net.PortNumber; |
| 40 | import org.onosproject.net.flow.TrafficSelector; |
| 41 | import org.onosproject.net.flow.TrafficTreatment; |
| 42 | import org.onosproject.net.flow.criteria.Criterion; |
| 43 | import org.onosproject.net.flow.criteria.EthTypeCriterion; |
| 44 | import org.onosproject.net.flow.criteria.PortCriterion; |
| 45 | import org.onosproject.net.flow.criteria.VlanIdCriterion; |
| 46 | import org.onosproject.net.flow.instructions.Instruction; |
| 47 | import org.onosproject.net.flow.instructions.Instructions; |
| 48 | import org.onosproject.net.flow.instructions.L2ModificationInstruction; |
| 49 | import org.onosproject.net.flowobjective.FilteringObjQueueKey; |
| 50 | import org.onosproject.net.flowobjective.FilteringObjective; |
| 51 | import org.onosproject.net.flowobjective.ForwardingObjQueueKey; |
| 52 | import org.onosproject.net.flowobjective.ForwardingObjective; |
| 53 | import org.onosproject.net.flowobjective.NextObjQueueKey; |
| 54 | import org.onosproject.net.flowobjective.NextObjective; |
| 55 | import org.onosproject.net.flowobjective.Objective; |
| 56 | import org.onosproject.net.meter.MeterId; |
| 57 | import org.onosproject.net.meter.MeterKey; |
| 58 | import org.opencord.sadis.BandwidthProfileInformation; |
| 59 | import org.opencord.sadis.UniTagInformation; |
| 60 | |
Saurav Das | f62cea8 | 2020-08-26 17:43:04 -0700 | [diff] [blame] | 61 | import com.google.common.collect.ImmutableList; |
| 62 | import com.google.common.collect.ImmutableMap; |
| 63 | import com.google.common.collect.ImmutableSet; |
| 64 | import com.google.common.collect.ListMultimap; |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 65 | |
| 66 | public class OltFlowTest extends TestBase { |
| 67 | private OltFlowService oltFlowService; |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 68 | PortNumber uniPortNumber = PortNumber.portNumber(1); |
Andrea Campanella | 3a96ce8 | 2021-02-09 12:32:42 +0100 | [diff] [blame] | 69 | PortNumber uniPortNumber2 = PortNumber.portNumber(2); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 70 | PortNumber nniPortNumber = PortNumber.portNumber(65535); |
| 71 | |
Tunahan Sezen | a07fe96 | 2021-02-24 08:24:24 +0000 | [diff] [blame^] | 72 | MacAddress macAddress = MacAddress.valueOf("00:00:00:00:0a:0b"); |
| 73 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 74 | 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 Das | f62cea8 | 2020-08-26 17:43:04 -0700 | [diff] [blame] | 83 | .setIsDhcpRequired(true) |
| 84 | .setIsIgmpRequired(true) |
| 85 | .build(); |
| 86 | |
Andrea Campanella | 3a96ce8 | 2021-02-09 12:32:42 +0100 | [diff] [blame] | 87 | 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 Das | f62cea8 | 2020-08-26 17:43:04 -0700 | [diff] [blame] | 102 | 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 Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 112 | .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 Ozdemir | 90a9362 | 2021-02-25 09:40:58 +0000 | [diff] [blame] | 123 | oltFlowService.pendingEapolForDevice = Maps.newConcurrentMap(); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | @Test |
| 127 | public void testDhcpFiltering() { |
Saurav Das | f62cea8 | 2020-08-26 17:43:04 -0700 | [diff] [blame] | 128 | oltFlowService.flowObjectiveService.clearQueue(); |
| 129 | // ensure upstream dhcp traps can be added and removed |
| 130 | oltFlowService.processDhcpFilteringObjectives(DEVICE_ID_1, uniPortNumber, |
Ilayda Ozdemir | 90a9362 | 2021-02-25 09:40:58 +0000 | [diff] [blame] | 131 | usMeterId, uniTagInfo, |
Tunahan Sezen | a07fe96 | 2021-02-24 08:24:24 +0000 | [diff] [blame^] | 132 | true, true, Optional.empty()); |
Saurav Das | f62cea8 | 2020-08-26 17:43:04 -0700 | [diff] [blame] | 133 | assert oltFlowService.flowObjectiveService.getPendingFlowObjectives().size() == 1; |
| 134 | oltFlowService.processDhcpFilteringObjectives(DEVICE_ID_1, uniPortNumber, |
Ilayda Ozdemir | 90a9362 | 2021-02-25 09:40:58 +0000 | [diff] [blame] | 135 | usMeterId, uniTagInfo, |
Tunahan Sezen | a07fe96 | 2021-02-24 08:24:24 +0000 | [diff] [blame^] | 136 | false, true, Optional.empty()); |
Saurav Das | f62cea8 | 2020-08-26 17:43:04 -0700 | [diff] [blame] | 137 | assert oltFlowService.flowObjectiveService.getPendingFlowObjectives().size() == 2; |
Andrea Campanella | 3a96ce8 | 2021-02-09 12:32:42 +0100 | [diff] [blame] | 138 | |
| 139 | // Ensure upstream flow has no pcp unless properly specified. |
| 140 | oltFlowService.processDhcpFilteringObjectives(DEVICE_ID_1, uniPortNumber2, |
Ilayda Ozdemir | 90a9362 | 2021-02-25 09:40:58 +0000 | [diff] [blame] | 141 | usMeterId, uniTagInfoNoPcp, |
Tunahan Sezen | a07fe96 | 2021-02-24 08:24:24 +0000 | [diff] [blame^] | 142 | true, true, Optional.empty()); |
Andrea Campanella | 3a96ce8 | 2021-02-09 12:32:42 +0100 | [diff] [blame] | 143 | assert oltFlowService.flowObjectiveService.getPendingFlowObjectives().size() == 3; |
| 144 | |
Saurav Das | f62cea8 | 2020-08-26 17:43:04 -0700 | [diff] [blame] | 145 | // ensure upstream flows are not added if uniTagInfo is missing dhcp requirement |
| 146 | oltFlowService.processDhcpFilteringObjectives(DEVICE_ID_1, uniPortNumber, |
Ilayda Ozdemir | 90a9362 | 2021-02-25 09:40:58 +0000 | [diff] [blame] | 147 | usMeterId, uniTagInfoNoDhcpNoIgmp, |
Tunahan Sezen | a07fe96 | 2021-02-24 08:24:24 +0000 | [diff] [blame^] | 148 | true, true, Optional.empty()); |
Andrea Campanella | 3a96ce8 | 2021-02-09 12:32:42 +0100 | [diff] [blame] | 149 | assert oltFlowService.flowObjectiveService.getPendingFlowObjectives().size() == 3; |
Saurav Das | f62cea8 | 2020-08-26 17:43:04 -0700 | [diff] [blame] | 150 | |
| 151 | // ensure downstream traps don't succeed without global config for nni ports |
| 152 | oltFlowService.processDhcpFilteringObjectives(DEVICE_ID_1, nniPortNumber, |
Ilayda Ozdemir | 90a9362 | 2021-02-25 09:40:58 +0000 | [diff] [blame] | 153 | null, null, |
Tunahan Sezen | a07fe96 | 2021-02-24 08:24:24 +0000 | [diff] [blame^] | 154 | true, false, Optional.empty()); |
Saurav Das | f62cea8 | 2020-08-26 17:43:04 -0700 | [diff] [blame] | 155 | oltFlowService.processDhcpFilteringObjectives(DEVICE_ID_1, nniPortNumber, |
Ilayda Ozdemir | 90a9362 | 2021-02-25 09:40:58 +0000 | [diff] [blame] | 156 | null, null, |
Tunahan Sezen | a07fe96 | 2021-02-24 08:24:24 +0000 | [diff] [blame^] | 157 | false, false, Optional.empty()); |
Andrea Campanella | 3a96ce8 | 2021-02-09 12:32:42 +0100 | [diff] [blame] | 158 | assert oltFlowService.flowObjectiveService.getPendingFlowObjectives().size() == 3; |
Saurav Das | f62cea8 | 2020-08-26 17:43:04 -0700 | [diff] [blame] | 159 | // do global config for nni ports and now it should succeed |
| 160 | oltFlowService.enableDhcpOnNni = true; |
| 161 | oltFlowService.processDhcpFilteringObjectives(DEVICE_ID_1, nniPortNumber, |
Ilayda Ozdemir | 90a9362 | 2021-02-25 09:40:58 +0000 | [diff] [blame] | 162 | null, null, |
Tunahan Sezen | a07fe96 | 2021-02-24 08:24:24 +0000 | [diff] [blame^] | 163 | true, false, Optional.empty()); |
Saurav Das | f62cea8 | 2020-08-26 17:43:04 -0700 | [diff] [blame] | 164 | oltFlowService.processDhcpFilteringObjectives(DEVICE_ID_1, nniPortNumber, |
Ilayda Ozdemir | 90a9362 | 2021-02-25 09:40:58 +0000 | [diff] [blame] | 165 | null, null, |
Tunahan Sezen | a07fe96 | 2021-02-24 08:24:24 +0000 | [diff] [blame^] | 166 | false, false, Optional.empty()); |
Andrea Campanella | 3a96ce8 | 2021-02-09 12:32:42 +0100 | [diff] [blame] | 167 | assert oltFlowService.flowObjectiveService.getPendingFlowObjectives().size() == 5; |
Saurav Das | f62cea8 | 2020-08-26 17:43:04 -0700 | [diff] [blame] | 168 | |
| 169 | // turn on DHCPv6 and we should get 2 flows |
| 170 | oltFlowService.enableDhcpV6 = true; |
| 171 | oltFlowService.processDhcpFilteringObjectives(DEVICE_ID_1, uniPortNumber, |
Ilayda Ozdemir | 90a9362 | 2021-02-25 09:40:58 +0000 | [diff] [blame] | 172 | usMeterId, uniTagInfo, |
Tunahan Sezen | a07fe96 | 2021-02-24 08:24:24 +0000 | [diff] [blame^] | 173 | true, true, Optional.empty()); |
Andrea Campanella | 3a96ce8 | 2021-02-09 12:32:42 +0100 | [diff] [blame] | 174 | assert oltFlowService.flowObjectiveService.getPendingFlowObjectives().size() == 7; |
Saurav Das | f62cea8 | 2020-08-26 17:43:04 -0700 | [diff] [blame] | 175 | |
| 176 | // turn off DHCPv4 and it's only v6 |
| 177 | oltFlowService.enableDhcpV4 = false; |
| 178 | oltFlowService.processDhcpFilteringObjectives(DEVICE_ID_1, uniPortNumber, |
Ilayda Ozdemir | 90a9362 | 2021-02-25 09:40:58 +0000 | [diff] [blame] | 179 | usMeterId, uniTagInfo, |
Tunahan Sezen | a07fe96 | 2021-02-24 08:24:24 +0000 | [diff] [blame^] | 180 | true, true, Optional.empty()); |
Andrea Campanella | 3a96ce8 | 2021-02-09 12:32:42 +0100 | [diff] [blame] | 181 | assert oltFlowService.flowObjectiveService.getPendingFlowObjectives().size() == 8; |
Saurav Das | f62cea8 | 2020-08-26 17:43:04 -0700 | [diff] [blame] | 182 | |
| 183 | // cleanup |
| 184 | oltFlowService.flowObjectiveService.clearQueue(); |
| 185 | oltFlowService.enableDhcpV4 = true; |
| 186 | oltFlowService.enableDhcpV6 = false; |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 187 | } |
| 188 | |
| 189 | @Test |
Gustavo Silva | 5c492dd | 2021-02-12 10:21:11 -0300 | [diff] [blame] | 190 | 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 Ozdemir | 90a9362 | 2021-02-25 09:40:58 +0000 | [diff] [blame] | 196 | usMeterId, uniTagInfo, |
| 197 | true, true); |
Gustavo Silva | 5c492dd | 2021-02-12 10:21:11 -0300 | [diff] [blame] | 198 | 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 Ozdemir | 90a9362 | 2021-02-25 09:40:58 +0000 | [diff] [blame] | 203 | usMeterId, uniTagInfo, |
| 204 | true, true); |
Gustavo Silva | 5c492dd | 2021-02-12 10:21:11 -0300 | [diff] [blame] | 205 | assert oltFlowService.flowObjectiveService.getPendingFlowObjectives().size() == 1; |
| 206 | oltFlowService.processPPPoEDFilteringObjectives(DEVICE_ID_1, uniPortNumber, |
Ilayda Ozdemir | 90a9362 | 2021-02-25 09:40:58 +0000 | [diff] [blame] | 207 | usMeterId, uniTagInfo, |
| 208 | false, true); |
Gustavo Silva | 5c492dd | 2021-02-12 10:21:11 -0300 | [diff] [blame] | 209 | 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 Ozdemir | 90a9362 | 2021-02-25 09:40:58 +0000 | [diff] [blame] | 213 | null, null, |
| 214 | true, false); |
Gustavo Silva | 5c492dd | 2021-02-12 10:21:11 -0300 | [diff] [blame] | 215 | assert oltFlowService.flowObjectiveService.getPendingFlowObjectives().size() == 3; |
| 216 | oltFlowService.processPPPoEDFilteringObjectives(DEVICE_ID_1, nniPortNumber, |
Ilayda Ozdemir | 90a9362 | 2021-02-25 09:40:58 +0000 | [diff] [blame] | 217 | null, null, |
| 218 | false, false); |
Gustavo Silva | 5c492dd | 2021-02-12 10:21:11 -0300 | [diff] [blame] | 219 | assert oltFlowService.flowObjectiveService.getPendingFlowObjectives().size() == 4; |
| 220 | |
| 221 | // cleanup |
| 222 | oltFlowService.flowObjectiveService.clearQueue(); |
| 223 | } |
| 224 | |
| 225 | @Test |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 226 | public void testIgmpFiltering() { |
Saurav Das | f62cea8 | 2020-08-26 17:43:04 -0700 | [diff] [blame] | 227 | oltFlowService.flowObjectiveService.clearQueue(); |
| 228 | |
| 229 | // ensure igmp flows can be added and removed |
| 230 | oltFlowService.processIgmpFilteringObjectives(DEVICE_ID_1, uniPortNumber, |
Ilayda Ozdemir | 90a9362 | 2021-02-25 09:40:58 +0000 | [diff] [blame] | 231 | usMeterId, uniTagInfo, |
| 232 | true, true); |
Saurav Das | f62cea8 | 2020-08-26 17:43:04 -0700 | [diff] [blame] | 233 | assert oltFlowService.flowObjectiveService.getPendingFlowObjectives().size() == 1; |
| 234 | oltFlowService.processIgmpFilteringObjectives(DEVICE_ID_1, uniPortNumber, usMeterId, |
Ilayda Ozdemir | 90a9362 | 2021-02-25 09:40:58 +0000 | [diff] [blame] | 235 | uniTagInfo, |
| 236 | false, true); |
Saurav Das | f62cea8 | 2020-08-26 17:43:04 -0700 | [diff] [blame] | 237 | 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 Ozdemir | 90a9362 | 2021-02-25 09:40:58 +0000 | [diff] [blame] | 241 | usMeterId, uniTagInfoNoDhcpNoIgmp, |
| 242 | true, true); |
Saurav Das | f62cea8 | 2020-08-26 17:43:04 -0700 | [diff] [blame] | 243 | 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 Ozdemir | 90a9362 | 2021-02-25 09:40:58 +0000 | [diff] [blame] | 247 | null, null, |
| 248 | true, false); |
Saurav Das | f62cea8 | 2020-08-26 17:43:04 -0700 | [diff] [blame] | 249 | 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 Ozdemir | 90a9362 | 2021-02-25 09:40:58 +0000 | [diff] [blame] | 254 | null, null, |
| 255 | true, false); |
Saurav Das | f62cea8 | 2020-08-26 17:43:04 -0700 | [diff] [blame] | 256 | assert oltFlowService.flowObjectiveService.getPendingFlowObjectives().size() == 3; |
| 257 | // cleanup |
| 258 | oltFlowService.flowObjectiveService.clearQueue(); |
| 259 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 260 | } |
| 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 Das | f62cea8 | 2020-08-26 17:43:04 -0700 | [diff] [blame] | 286 | oltFlowService.flowObjectiveService.clearQueue(); |
| 287 | oltFlowService.enableDhcpOnNni = true; |
| 288 | oltFlowService.enableIgmpOnNni = true; |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 289 | oltFlowService.processNniFilteringObjectives(DEVICE_ID_1, nniPortNumber, true); |
Saurav Das | f62cea8 | 2020-08-26 17:43:04 -0700 | [diff] [blame] | 290 | assert oltFlowService.flowObjectiveService.getPendingFlowObjectives() |
| 291 | .size() == 3; |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 292 | oltFlowService.processNniFilteringObjectives(DEVICE_ID_1, nniPortNumber, false); |
Saurav Das | f62cea8 | 2020-08-26 17:43:04 -0700 | [diff] [blame] | 293 | assert oltFlowService.flowObjectiveService.getPendingFlowObjectives() |
| 294 | .size() == 6; |
| 295 | oltFlowService.flowObjectiveService.clearQueue(); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 296 | } |
| 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 Sezen | a07fe96 | 2021-02-24 08:24:24 +0000 | [diff] [blame^] | 308 | oltFlowService.createDownBuilder(nniPortNumber, uniPortNumber, dsMeterId, uniTagInfo, |
| 309 | Optional.of(macAddress)).remove(); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 310 | 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 Ozdemir | 90a9362 | 2021-02-25 09:40:58 +0000 | [diff] [blame] | 340 | assert selector.getCriterion(Criterion.Type.METADATA) != null; |
Tunahan Sezen | a07fe96 | 2021-02-24 08:24:24 +0000 | [diff] [blame^] | 341 | assert selector.getCriterion(Criterion.Type.ETH_DST) != null; |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 342 | } |
| 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 Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 352 | 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 Hart | 4f178fa | 2020-02-03 10:46:01 -0800 | [diff] [blame] | 367 | |
| 368 | @Override |
Andrea Campanella | 600d2e2 | 2020-06-22 11:00:31 +0200 | [diff] [blame] | 369 | public void removeFromPendingMeters(DeviceId deviceId, BandwidthProfileInformation bwpInfo) { |
| 370 | |
Andrea Campanella | 3ce4d28 | 2020-06-09 13:46:58 +0200 | [diff] [blame] | 371 | } |
| 372 | |
| 373 | @Override |
Andrea Campanella | d1e2664 | 2020-10-23 12:08:32 +0200 | [diff] [blame] | 374 | public boolean checkAndAddPendingMeter(DeviceId deviceId, BandwidthProfileInformation bwpInfo) { |
Andrea Campanella | 3ce4d28 | 2020-06-09 13:46:58 +0200 | [diff] [blame] | 375 | return false; |
| 376 | } |
| 377 | |
Andrea Campanella | 600d2e2 | 2020-06-22 11:00:31 +0200 | [diff] [blame] | 378 | |
Andrea Campanella | 3ce4d28 | 2020-06-09 13:46:58 +0200 | [diff] [blame] | 379 | @Override |
Jonathan Hart | 4f178fa | 2020-02-03 10:46:01 -0800 | [diff] [blame] | 380 | public void clearMeters(DeviceId deviceId) { |
| 381 | } |
Andrea Campanella | 600d2e2 | 2020-06-22 11:00:31 +0200 | [diff] [blame] | 382 | |
| 383 | @Override |
| 384 | public void clearDeviceState(DeviceId deviceId) { |
| 385 | |
| 386 | } |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 387 | } |
| 388 | |
| 389 | private class MockOltFlowObjectiveService implements org.onosproject.net.flowobjective.FlowObjectiveService { |
Saurav Das | f62cea8 | 2020-08-26 17:43:04 -0700 | [diff] [blame] | 390 | List<String> flowObjectives = new ArrayList<>(); |
| 391 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 392 | @Override |
| 393 | public void filter(DeviceId deviceId, FilteringObjective filteringObjective) { |
Saurav Das | f62cea8 | 2020-08-26 17:43:04 -0700 | [diff] [blame] | 394 | flowObjectives.add(filteringObjective.toString()); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 395 | 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 Campanella | 3a96ce8 | 2021-02-09 12:32:42 +0100 | [diff] [blame] | 404 | 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 Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 414 | |
| 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 Campanella | 3a96ce8 | 2021-02-09 12:32:42 +0100 | [diff] [blame] | 423 | assert vlanIdCriterion == null || vlanIdCriterion.vlanId() == uniTagInfo.getUniTagMatch() |
| 424 | || vlanIdCriterion.vlanId() == uniTagInfoNoPcp.getUniTagMatch(); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 425 | } |
| 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 Das | f62cea8 | 2020-08-26 17:43:04 -0700 | [diff] [blame] | 466 | return ImmutableList.copyOf(flowObjectives); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 467 | } |
| 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 Das | f62cea8 | 2020-08-26 17:43:04 -0700 | [diff] [blame] | 501 | flowObjectives.clear(); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 502 | } |
| 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 | } |