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; |
Tunahan Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame] | 37 | import org.onosproject.net.AnnotationKeys; |
| 38 | import org.onosproject.net.DefaultAnnotations; |
| 39 | import org.onosproject.net.DefaultPort; |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 40 | import org.onosproject.net.DeviceId; |
| 41 | import org.onosproject.net.MastershipRole; |
| 42 | import org.onosproject.net.PortNumber; |
| 43 | import org.onosproject.net.flow.TrafficSelector; |
| 44 | import org.onosproject.net.flow.TrafficTreatment; |
| 45 | import org.onosproject.net.flow.criteria.Criterion; |
| 46 | import org.onosproject.net.flow.criteria.EthTypeCriterion; |
| 47 | import org.onosproject.net.flow.criteria.PortCriterion; |
| 48 | import org.onosproject.net.flow.criteria.VlanIdCriterion; |
| 49 | import org.onosproject.net.flow.instructions.Instruction; |
| 50 | import org.onosproject.net.flow.instructions.Instructions; |
| 51 | import org.onosproject.net.flow.instructions.L2ModificationInstruction; |
| 52 | import org.onosproject.net.flowobjective.FilteringObjQueueKey; |
| 53 | import org.onosproject.net.flowobjective.FilteringObjective; |
| 54 | import org.onosproject.net.flowobjective.ForwardingObjQueueKey; |
| 55 | import org.onosproject.net.flowobjective.ForwardingObjective; |
| 56 | import org.onosproject.net.flowobjective.NextObjQueueKey; |
| 57 | import org.onosproject.net.flowobjective.NextObjective; |
| 58 | import org.onosproject.net.flowobjective.Objective; |
| 59 | import org.onosproject.net.meter.MeterId; |
| 60 | import org.onosproject.net.meter.MeterKey; |
Tunahan Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame] | 61 | import org.opencord.olt.AccessDevicePort; |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 62 | import org.opencord.sadis.BandwidthProfileInformation; |
| 63 | import org.opencord.sadis.UniTagInformation; |
| 64 | |
Saurav Das | f62cea8 | 2020-08-26 17:43:04 -0700 | [diff] [blame] | 65 | import com.google.common.collect.ImmutableList; |
| 66 | import com.google.common.collect.ImmutableMap; |
| 67 | import com.google.common.collect.ImmutableSet; |
| 68 | import com.google.common.collect.ListMultimap; |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 69 | |
| 70 | public class OltFlowTest extends TestBase { |
| 71 | private OltFlowService oltFlowService; |
Tunahan Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame] | 72 | 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 Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 81 | |
Tunahan Sezen | a07fe96 | 2021-02-24 08:24:24 +0000 | [diff] [blame] | 82 | MacAddress macAddress = MacAddress.valueOf("00:00:00:00:0a:0b"); |
| 83 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 84 | 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 Das | f62cea8 | 2020-08-26 17:43:04 -0700 | [diff] [blame] | 93 | .setIsDhcpRequired(true) |
| 94 | .setIsIgmpRequired(true) |
| 95 | .build(); |
| 96 | |
Andrea Campanella | 3a96ce8 | 2021-02-09 12:32:42 +0100 | [diff] [blame] | 97 | 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 Das | f62cea8 | 2020-08-26 17:43:04 -0700 | [diff] [blame] | 112 | 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 Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 122 | .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 Ozdemir | 90a9362 | 2021-02-25 09:40:58 +0000 | [diff] [blame] | 133 | oltFlowService.pendingEapolForDevice = Maps.newConcurrentMap(); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | @Test |
| 137 | public void testDhcpFiltering() { |
Tunahan Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame] | 138 | System.out.println(uniPort1); |
Saurav Das | f62cea8 | 2020-08-26 17:43:04 -0700 | [diff] [blame] | 139 | oltFlowService.flowObjectiveService.clearQueue(); |
| 140 | // ensure upstream dhcp traps can be added and removed |
Tunahan Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame] | 141 | oltFlowService.processDhcpFilteringObjectives(uniPort1, |
yasin sapli | b4b8ee1 | 2021-06-13 18:25:20 +0000 | [diff] [blame] | 142 | usMeterId, null, uniTagInfo, |
Tunahan Sezen | a07fe96 | 2021-02-24 08:24:24 +0000 | [diff] [blame] | 143 | true, true, Optional.empty()); |
Saurav Das | f62cea8 | 2020-08-26 17:43:04 -0700 | [diff] [blame] | 144 | assert oltFlowService.flowObjectiveService.getPendingFlowObjectives().size() == 1; |
Tunahan Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame] | 145 | oltFlowService.processDhcpFilteringObjectives(uniPort1, |
yasin sapli | b4b8ee1 | 2021-06-13 18:25:20 +0000 | [diff] [blame] | 146 | usMeterId, null, uniTagInfo, |
Tunahan Sezen | a07fe96 | 2021-02-24 08:24:24 +0000 | [diff] [blame] | 147 | false, true, Optional.empty()); |
Saurav Das | f62cea8 | 2020-08-26 17:43:04 -0700 | [diff] [blame] | 148 | assert oltFlowService.flowObjectiveService.getPendingFlowObjectives().size() == 2; |
Andrea Campanella | 3a96ce8 | 2021-02-09 12:32:42 +0100 | [diff] [blame] | 149 | |
| 150 | // Ensure upstream flow has no pcp unless properly specified. |
Tunahan Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame] | 151 | oltFlowService.processDhcpFilteringObjectives(uniPort2, |
yasin sapli | b4b8ee1 | 2021-06-13 18:25:20 +0000 | [diff] [blame] | 152 | usMeterId, null, uniTagInfoNoPcp, |
Tunahan Sezen | a07fe96 | 2021-02-24 08:24:24 +0000 | [diff] [blame] | 153 | true, true, Optional.empty()); |
Andrea Campanella | 3a96ce8 | 2021-02-09 12:32:42 +0100 | [diff] [blame] | 154 | assert oltFlowService.flowObjectiveService.getPendingFlowObjectives().size() == 3; |
| 155 | |
Saurav Das | f62cea8 | 2020-08-26 17:43:04 -0700 | [diff] [blame] | 156 | // ensure upstream flows are not added if uniTagInfo is missing dhcp requirement |
Tunahan Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame] | 157 | oltFlowService.processDhcpFilteringObjectives(uniPort1, |
yasin sapli | b4b8ee1 | 2021-06-13 18:25:20 +0000 | [diff] [blame] | 158 | usMeterId, null, uniTagInfoNoDhcpNoIgmp, |
Tunahan Sezen | a07fe96 | 2021-02-24 08:24:24 +0000 | [diff] [blame] | 159 | true, true, Optional.empty()); |
Andrea Campanella | 3a96ce8 | 2021-02-09 12:32:42 +0100 | [diff] [blame] | 160 | assert oltFlowService.flowObjectiveService.getPendingFlowObjectives().size() == 3; |
Saurav Das | f62cea8 | 2020-08-26 17:43:04 -0700 | [diff] [blame] | 161 | |
| 162 | // ensure downstream traps don't succeed without global config for nni ports |
Tunahan Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame] | 163 | oltFlowService.processDhcpFilteringObjectives(nniPort, |
yasin sapli | b4b8ee1 | 2021-06-13 18:25:20 +0000 | [diff] [blame] | 164 | null, null, null, |
Tunahan Sezen | a07fe96 | 2021-02-24 08:24:24 +0000 | [diff] [blame] | 165 | true, false, Optional.empty()); |
Tunahan Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame] | 166 | oltFlowService.processDhcpFilteringObjectives(nniPort, |
yasin sapli | b4b8ee1 | 2021-06-13 18:25:20 +0000 | [diff] [blame] | 167 | null, null, null, |
Tunahan Sezen | a07fe96 | 2021-02-24 08:24:24 +0000 | [diff] [blame] | 168 | false, false, Optional.empty()); |
Andrea Campanella | 3a96ce8 | 2021-02-09 12:32:42 +0100 | [diff] [blame] | 169 | assert oltFlowService.flowObjectiveService.getPendingFlowObjectives().size() == 3; |
Saurav Das | f62cea8 | 2020-08-26 17:43:04 -0700 | [diff] [blame] | 170 | // do global config for nni ports and now it should succeed |
| 171 | oltFlowService.enableDhcpOnNni = true; |
Tunahan Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame] | 172 | oltFlowService.processDhcpFilteringObjectives(nniPort, |
yasin sapli | b4b8ee1 | 2021-06-13 18:25:20 +0000 | [diff] [blame] | 173 | null, null, null, |
Tunahan Sezen | a07fe96 | 2021-02-24 08:24:24 +0000 | [diff] [blame] | 174 | true, false, Optional.empty()); |
Tunahan Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame] | 175 | oltFlowService.processDhcpFilteringObjectives(nniPort, |
yasin sapli | b4b8ee1 | 2021-06-13 18:25:20 +0000 | [diff] [blame] | 176 | null, null, null, |
Tunahan Sezen | a07fe96 | 2021-02-24 08:24:24 +0000 | [diff] [blame] | 177 | false, false, Optional.empty()); |
Andrea Campanella | 3a96ce8 | 2021-02-09 12:32:42 +0100 | [diff] [blame] | 178 | assert oltFlowService.flowObjectiveService.getPendingFlowObjectives().size() == 5; |
Saurav Das | f62cea8 | 2020-08-26 17:43:04 -0700 | [diff] [blame] | 179 | |
| 180 | // turn on DHCPv6 and we should get 2 flows |
| 181 | oltFlowService.enableDhcpV6 = true; |
Tunahan Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame] | 182 | oltFlowService.processDhcpFilteringObjectives(uniPort1, |
yasin sapli | b4b8ee1 | 2021-06-13 18:25:20 +0000 | [diff] [blame] | 183 | usMeterId, null, uniTagInfo, |
Tunahan Sezen | a07fe96 | 2021-02-24 08:24:24 +0000 | [diff] [blame] | 184 | true, true, Optional.empty()); |
Andrea Campanella | 3a96ce8 | 2021-02-09 12:32:42 +0100 | [diff] [blame] | 185 | assert oltFlowService.flowObjectiveService.getPendingFlowObjectives().size() == 7; |
Saurav Das | f62cea8 | 2020-08-26 17:43:04 -0700 | [diff] [blame] | 186 | |
| 187 | // turn off DHCPv4 and it's only v6 |
| 188 | oltFlowService.enableDhcpV4 = false; |
Tunahan Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame] | 189 | oltFlowService.processDhcpFilteringObjectives(uniPort1, |
yasin sapli | b4b8ee1 | 2021-06-13 18:25:20 +0000 | [diff] [blame] | 190 | usMeterId, null, uniTagInfo, |
Tunahan Sezen | a07fe96 | 2021-02-24 08:24:24 +0000 | [diff] [blame] | 191 | true, true, Optional.empty()); |
Andrea Campanella | 3a96ce8 | 2021-02-09 12:32:42 +0100 | [diff] [blame] | 192 | assert oltFlowService.flowObjectiveService.getPendingFlowObjectives().size() == 8; |
Saurav Das | f62cea8 | 2020-08-26 17:43:04 -0700 | [diff] [blame] | 193 | |
| 194 | // cleanup |
| 195 | oltFlowService.flowObjectiveService.clearQueue(); |
| 196 | oltFlowService.enableDhcpV4 = true; |
| 197 | oltFlowService.enableDhcpV6 = false; |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 198 | } |
| 199 | |
| 200 | @Test |
Gustavo Silva | 5c492dd | 2021-02-12 10:21:11 -0300 | [diff] [blame] | 201 | 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 Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame] | 206 | oltFlowService.processPPPoEDFilteringObjectives(uniPort1, |
yasin sapli | b4b8ee1 | 2021-06-13 18:25:20 +0000 | [diff] [blame] | 207 | usMeterId, null, uniTagInfo, |
Ilayda Ozdemir | 90a9362 | 2021-02-25 09:40:58 +0000 | [diff] [blame] | 208 | true, true); |
Gustavo Silva | 5c492dd | 2021-02-12 10:21:11 -0300 | [diff] [blame] | 209 | assert oltFlowService.flowObjectiveService.getPendingFlowObjectives().size() == 0; |
| 210 | |
| 211 | // ensure upstream pppoed traps can be added and removed |
| 212 | oltFlowService.enablePppoe = true; |
Tunahan Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame] | 213 | oltFlowService.processPPPoEDFilteringObjectives(uniPort1, |
yasin sapli | b4b8ee1 | 2021-06-13 18:25:20 +0000 | [diff] [blame] | 214 | usMeterId, null, uniTagInfo, |
Ilayda Ozdemir | 90a9362 | 2021-02-25 09:40:58 +0000 | [diff] [blame] | 215 | true, true); |
Gustavo Silva | 5c492dd | 2021-02-12 10:21:11 -0300 | [diff] [blame] | 216 | assert oltFlowService.flowObjectiveService.getPendingFlowObjectives().size() == 1; |
Tunahan Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame] | 217 | oltFlowService.processPPPoEDFilteringObjectives(uniPort1, |
yasin sapli | b4b8ee1 | 2021-06-13 18:25:20 +0000 | [diff] [blame] | 218 | usMeterId, null, uniTagInfo, |
Ilayda Ozdemir | 90a9362 | 2021-02-25 09:40:58 +0000 | [diff] [blame] | 219 | false, true); |
Gustavo Silva | 5c492dd | 2021-02-12 10:21:11 -0300 | [diff] [blame] | 220 | assert oltFlowService.flowObjectiveService.getPendingFlowObjectives().size() == 2; |
| 221 | |
| 222 | // ensure downstream pppoed traps can be added and removed |
Tunahan Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame] | 223 | oltFlowService.processPPPoEDFilteringObjectives(nniPort, |
yasin sapli | b4b8ee1 | 2021-06-13 18:25:20 +0000 | [diff] [blame] | 224 | null, null, null, |
Ilayda Ozdemir | 90a9362 | 2021-02-25 09:40:58 +0000 | [diff] [blame] | 225 | true, false); |
Gustavo Silva | 5c492dd | 2021-02-12 10:21:11 -0300 | [diff] [blame] | 226 | assert oltFlowService.flowObjectiveService.getPendingFlowObjectives().size() == 3; |
Tunahan Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame] | 227 | oltFlowService.processPPPoEDFilteringObjectives(nniPort, |
yasin sapli | b4b8ee1 | 2021-06-13 18:25:20 +0000 | [diff] [blame] | 228 | null, null, null, |
Ilayda Ozdemir | 90a9362 | 2021-02-25 09:40:58 +0000 | [diff] [blame] | 229 | false, false); |
Gustavo Silva | 5c492dd | 2021-02-12 10:21:11 -0300 | [diff] [blame] | 230 | assert oltFlowService.flowObjectiveService.getPendingFlowObjectives().size() == 4; |
| 231 | |
| 232 | // cleanup |
| 233 | oltFlowService.flowObjectiveService.clearQueue(); |
| 234 | } |
| 235 | |
| 236 | @Test |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 237 | public void testIgmpFiltering() { |
Saurav Das | f62cea8 | 2020-08-26 17:43:04 -0700 | [diff] [blame] | 238 | oltFlowService.flowObjectiveService.clearQueue(); |
| 239 | |
| 240 | // ensure igmp flows can be added and removed |
Tunahan Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame] | 241 | oltFlowService.processIgmpFilteringObjectives(uniPort1, |
yasin sapli | b4b8ee1 | 2021-06-13 18:25:20 +0000 | [diff] [blame] | 242 | usMeterId, null, uniTagInfo, |
Ilayda Ozdemir | 90a9362 | 2021-02-25 09:40:58 +0000 | [diff] [blame] | 243 | true, true); |
Saurav Das | f62cea8 | 2020-08-26 17:43:04 -0700 | [diff] [blame] | 244 | assert oltFlowService.flowObjectiveService.getPendingFlowObjectives().size() == 1; |
Tunahan Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame] | 245 | oltFlowService.processIgmpFilteringObjectives(uniPort1, usMeterId, |
yasin sapli | b4b8ee1 | 2021-06-13 18:25:20 +0000 | [diff] [blame] | 246 | null, uniTagInfo, |
Ilayda Ozdemir | 90a9362 | 2021-02-25 09:40:58 +0000 | [diff] [blame] | 247 | false, true); |
Saurav Das | f62cea8 | 2020-08-26 17:43:04 -0700 | [diff] [blame] | 248 | assert oltFlowService.flowObjectiveService.getPendingFlowObjectives().size() == 2; |
| 249 | |
| 250 | // ensure igmp flow is not added if uniTag has no igmp requirement |
Tunahan Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame] | 251 | oltFlowService.processIgmpFilteringObjectives(uniPort1, |
yasin sapli | b4b8ee1 | 2021-06-13 18:25:20 +0000 | [diff] [blame] | 252 | usMeterId, null, uniTagInfoNoDhcpNoIgmp, |
Ilayda Ozdemir | 90a9362 | 2021-02-25 09:40:58 +0000 | [diff] [blame] | 253 | true, true); |
Saurav Das | f62cea8 | 2020-08-26 17:43:04 -0700 | [diff] [blame] | 254 | assert oltFlowService.flowObjectiveService.getPendingFlowObjectives().size() == 2; |
| 255 | |
| 256 | //ensure igmp flow on NNI fails without global setting |
Tunahan Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame] | 257 | oltFlowService.processIgmpFilteringObjectives(nniPort, |
yasin sapli | b4b8ee1 | 2021-06-13 18:25:20 +0000 | [diff] [blame] | 258 | null, null, null, |
Ilayda Ozdemir | 90a9362 | 2021-02-25 09:40:58 +0000 | [diff] [blame] | 259 | true, false); |
Saurav Das | f62cea8 | 2020-08-26 17:43:04 -0700 | [diff] [blame] | 260 | assert oltFlowService.flowObjectiveService.getPendingFlowObjectives().size() == 2; |
| 261 | |
| 262 | // igmp trap on NNI should succeed with global config |
| 263 | oltFlowService.enableIgmpOnNni = true; |
Tunahan Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame] | 264 | oltFlowService.processIgmpFilteringObjectives(nniPort, |
yasin sapli | b4b8ee1 | 2021-06-13 18:25:20 +0000 | [diff] [blame] | 265 | null, null, null, |
Ilayda Ozdemir | 90a9362 | 2021-02-25 09:40:58 +0000 | [diff] [blame] | 266 | true, false); |
Saurav Das | f62cea8 | 2020-08-26 17:43:04 -0700 | [diff] [blame] | 267 | assert oltFlowService.flowObjectiveService.getPendingFlowObjectives().size() == 3; |
| 268 | // cleanup |
| 269 | oltFlowService.flowObjectiveService.clearQueue(); |
| 270 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 271 | } |
| 272 | |
| 273 | @Test |
| 274 | public void testEapolFiltering() { |
| 275 | addBandwidthProfile(uniTagInfo.getUpstreamBandwidthProfile()); |
| 276 | oltFlowService.enableEapol = true; |
| 277 | |
| 278 | //will install |
Tunahan Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame] | 279 | oltFlowService.processEapolFilteringObjectives(uniPort1, |
yasin sapli | b4b8ee1 | 2021-06-13 18:25:20 +0000 | [diff] [blame] | 280 | uniTagInfo.getUpstreamBandwidthProfile(), Optional.empty(), new CompletableFuture<>(), |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 281 | uniTagInfo.getUniTagMatch(), true); |
| 282 | |
| 283 | //bp profile doesn't exist |
Tunahan Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame] | 284 | oltFlowService.processEapolFilteringObjectives(uniPort1, |
yasin sapli | b4b8ee1 | 2021-06-13 18:25:20 +0000 | [diff] [blame] | 285 | uniTagInfo.getDownstreamBandwidthProfile(), Optional.empty(), new CompletableFuture<>(), |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 286 | uniTagInfo.getUniTagMatch(), true); |
| 287 | } |
| 288 | |
| 289 | @Test |
| 290 | public void testLldpFiltering() { |
Tunahan Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame] | 291 | oltFlowService.processLldpFilteringObjective(nniPort, true); |
| 292 | oltFlowService.processLldpFilteringObjective(nniPort, false); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 293 | } |
| 294 | |
| 295 | @Test |
| 296 | public void testNniFiltering() { |
Saurav Das | f62cea8 | 2020-08-26 17:43:04 -0700 | [diff] [blame] | 297 | oltFlowService.flowObjectiveService.clearQueue(); |
| 298 | oltFlowService.enableDhcpOnNni = true; |
| 299 | oltFlowService.enableIgmpOnNni = true; |
Tunahan Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame] | 300 | oltFlowService.processNniFilteringObjectives(nniPort, true); |
Saurav Das | f62cea8 | 2020-08-26 17:43:04 -0700 | [diff] [blame] | 301 | assert oltFlowService.flowObjectiveService.getPendingFlowObjectives() |
| 302 | .size() == 3; |
Tunahan Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame] | 303 | oltFlowService.processNniFilteringObjectives(nniPort, false); |
Saurav Das | f62cea8 | 2020-08-26 17:43:04 -0700 | [diff] [blame] | 304 | assert oltFlowService.flowObjectiveService.getPendingFlowObjectives() |
| 305 | .size() == 6; |
| 306 | oltFlowService.flowObjectiveService.clearQueue(); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 307 | } |
| 308 | |
| 309 | @Test |
| 310 | public void testUpBuilder() { |
| 311 | ForwardingObjective objective = |
yasin sapli | b4b8ee1 | 2021-06-13 18:25:20 +0000 | [diff] [blame] | 312 | oltFlowService.createUpBuilder(nniPort, uniPort1, usMeterId, usMeterId, uniTagInfo).add(); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 313 | checkObjective(objective, true); |
| 314 | } |
| 315 | |
| 316 | @Test |
| 317 | public void testDownBuilder() { |
| 318 | ForwardingObjective objective = |
yasin sapli | b4b8ee1 | 2021-06-13 18:25:20 +0000 | [diff] [blame] | 319 | oltFlowService.createDownBuilder(nniPort, uniPort1, dsMeterId, dsMeterId, uniTagInfo, |
Tunahan Sezen | a07fe96 | 2021-02-24 08:24:24 +0000 | [diff] [blame] | 320 | Optional.of(macAddress)).remove(); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 321 | 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 Ozdemir | 90a9362 | 2021-02-25 09:40:58 +0000 | [diff] [blame] | 351 | assert selector.getCriterion(Criterion.Type.METADATA) != null; |
Tunahan Sezen | a07fe96 | 2021-02-24 08:24:24 +0000 | [diff] [blame] | 352 | assert selector.getCriterion(Criterion.Type.ETH_DST) != null; |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 353 | } |
| 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 Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 363 | 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 Hart | 4f178fa | 2020-02-03 10:46:01 -0800 | [diff] [blame] | 378 | |
| 379 | @Override |
Andrea Campanella | 600d2e2 | 2020-06-22 11:00:31 +0200 | [diff] [blame] | 380 | public void removeFromPendingMeters(DeviceId deviceId, BandwidthProfileInformation bwpInfo) { |
| 381 | |
Andrea Campanella | 3ce4d28 | 2020-06-09 13:46:58 +0200 | [diff] [blame] | 382 | } |
| 383 | |
| 384 | @Override |
Andrea Campanella | d1e2664 | 2020-10-23 12:08:32 +0200 | [diff] [blame] | 385 | public boolean checkAndAddPendingMeter(DeviceId deviceId, BandwidthProfileInformation bwpInfo) { |
Andrea Campanella | 3ce4d28 | 2020-06-09 13:46:58 +0200 | [diff] [blame] | 386 | return false; |
| 387 | } |
| 388 | |
Andrea Campanella | 600d2e2 | 2020-06-22 11:00:31 +0200 | [diff] [blame] | 389 | |
Andrea Campanella | 3ce4d28 | 2020-06-09 13:46:58 +0200 | [diff] [blame] | 390 | @Override |
Jonathan Hart | 4f178fa | 2020-02-03 10:46:01 -0800 | [diff] [blame] | 391 | public void clearMeters(DeviceId deviceId) { |
| 392 | } |
Andrea Campanella | 600d2e2 | 2020-06-22 11:00:31 +0200 | [diff] [blame] | 393 | |
| 394 | @Override |
| 395 | public void clearDeviceState(DeviceId deviceId) { |
| 396 | |
| 397 | } |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 398 | } |
| 399 | |
| 400 | private class MockOltFlowObjectiveService implements org.onosproject.net.flowobjective.FlowObjectiveService { |
Saurav Das | f62cea8 | 2020-08-26 17:43:04 -0700 | [diff] [blame] | 401 | List<String> flowObjectives = new ArrayList<>(); |
| 402 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 403 | @Override |
| 404 | public void filter(DeviceId deviceId, FilteringObjective filteringObjective) { |
Saurav Das | f62cea8 | 2020-08-26 17:43:04 -0700 | [diff] [blame] | 405 | flowObjectives.add(filteringObjective.toString()); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 406 | 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 Campanella | 3a96ce8 | 2021-02-09 12:32:42 +0100 | [diff] [blame] | 415 | 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 Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 425 | |
| 426 | if (ethType.ethType().equals(EthType.EtherType.LLDP.ethType()) || |
Tunahan Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame] | 427 | portCriterion.port().equals(nniPort.number())) { |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 428 | 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 Campanella | 3a96ce8 | 2021-02-09 12:32:42 +0100 | [diff] [blame] | 434 | assert vlanIdCriterion == null || vlanIdCriterion.vlanId() == uniTagInfo.getUniTagMatch() |
| 435 | || vlanIdCriterion.vlanId() == uniTagInfoNoPcp.getUniTagMatch(); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 436 | } |
| 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 Das | f62cea8 | 2020-08-26 17:43:04 -0700 | [diff] [blame] | 477 | return ImmutableList.copyOf(flowObjectives); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 478 | } |
| 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 Das | f62cea8 | 2020-08-26 17:43:04 -0700 | [diff] [blame] | 512 | flowObjectives.clear(); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 513 | } |
| 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 | } |