Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2021-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 | |
| 17 | package org.opencord.olt.impl; |
| 18 | |
| 19 | import com.google.common.collect.Maps; |
| 20 | import org.mockito.ArgumentMatcher; |
| 21 | import org.onosproject.net.Annotations; |
| 22 | import org.onosproject.net.Element; |
| 23 | import org.onosproject.net.Port; |
| 24 | import org.onosproject.net.PortNumber; |
| 25 | import org.onosproject.net.flowobjective.FilteringObjective; |
| 26 | import org.opencord.sadis.BandwidthProfileInformation; |
| 27 | |
| 28 | import java.util.Map; |
| 29 | |
| 30 | @SuppressWarnings("checkstyle:HideUtilityClassConstructor") |
| 31 | public class OltTestHelpers { |
| 32 | |
| 33 | protected static final String CLIENT_NAS_PORT_ID = "PON 1/1"; |
| 34 | protected static final String CLIENT_CIRCUIT_ID = "CIR-PON 1/1"; |
| 35 | protected static final String OLT_DEV_ID = "of:00000000000000aa"; |
| 36 | Map<String, BandwidthProfileInformation> bpInformation = Maps.newConcurrentMap(); |
| 37 | |
| 38 | protected class FilteringObjectiveMatcher extends ArgumentMatcher<FilteringObjective> { |
| 39 | |
| 40 | private FilteringObjective left; |
| 41 | |
| 42 | public FilteringObjectiveMatcher(FilteringObjective left) { |
| 43 | this.left = left; |
| 44 | } |
| 45 | |
| 46 | @Override |
| 47 | public boolean matches(Object right) { |
| 48 | // NOTE this matcher can be improved |
| 49 | FilteringObjective r = (FilteringObjective) right; |
| 50 | boolean matches = left.type().equals(r.type()) && |
| 51 | left.key().equals(r.key()) && |
| 52 | left.conditions().equals(r.conditions()) && |
| 53 | left.appId().equals(r.appId()) && |
| 54 | left.priority() == r.priority(); |
| 55 | |
| 56 | if (left.meta() != null) { |
| 57 | if (left.meta().equals(r.meta())) { |
| 58 | return matches; |
| 59 | } else { |
| 60 | return false; |
| 61 | } |
| 62 | } |
| 63 | return matches; |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | public class OltPort implements Port { |
| 68 | |
| 69 | public boolean enabled; |
| 70 | public PortNumber portNumber; |
| 71 | public Annotations annotations; |
| 72 | public Element element; |
| 73 | |
| 74 | public OltPort(Element element, boolean enabled, PortNumber portNumber, Annotations annotations) { |
| 75 | this.enabled = enabled; |
| 76 | this.portNumber = portNumber; |
| 77 | this.annotations = annotations; |
| 78 | this.element = element; |
| 79 | } |
| 80 | |
| 81 | @Override |
| 82 | public Element element() { |
| 83 | return element; |
| 84 | } |
| 85 | |
| 86 | @Override |
| 87 | public PortNumber number() { |
| 88 | return portNumber; |
| 89 | } |
| 90 | |
| 91 | @Override |
| 92 | public boolean isEnabled() { |
| 93 | return enabled; |
| 94 | } |
| 95 | |
| 96 | @Override |
| 97 | public Type type() { |
| 98 | return null; |
| 99 | } |
| 100 | |
| 101 | @Override |
| 102 | public long portSpeed() { |
| 103 | return 0; |
| 104 | } |
| 105 | |
| 106 | @Override |
| 107 | public Annotations annotations() { |
| 108 | return annotations; |
| 109 | } |
| 110 | } |
| 111 | } |