Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 1 | /* |
Joey Armstrong | 7f6d6d2 | 2023-01-09 17:09:50 -0500 | [diff] [blame^] | 2 | * Copyright 2021-2023 Open Networking Foundation (ONF) and the ONF Contributors |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 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 | |
Harsh Awasthi | c1e4bf5 | 2022-02-09 14:14:14 +0530 | [diff] [blame] | 19 | import org.onlab.packet.VlanId; |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 20 | import org.onosproject.net.AnnotationKeys; |
| 21 | import org.onosproject.net.Port; |
Gustavo Silva | 89e2f04 | 2022-08-01 09:58:04 -0300 | [diff] [blame] | 22 | import org.opencord.olt.AccessDevicePort; |
Gustavo Silva | 29fb20e | 2022-05-26 09:59:54 -0300 | [diff] [blame] | 23 | import org.opencord.olt.FlowOperation; |
Gustavo Silva | 89e2f04 | 2022-08-01 09:58:04 -0300 | [diff] [blame] | 24 | import org.opencord.olt.OltFlowServiceInterface; |
| 25 | import org.opencord.olt.ServiceKey; |
Harsh Awasthi | c1e4bf5 | 2022-02-09 14:14:14 +0530 | [diff] [blame] | 26 | import org.opencord.sadis.SubscriberAndDeviceInformation; |
| 27 | import org.opencord.sadis.UniTagInformation; |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 28 | |
Gustavo Silva | 89e2f04 | 2022-08-01 09:58:04 -0300 | [diff] [blame] | 29 | import java.util.List; |
| 30 | import java.util.Map; |
| 31 | import java.util.stream.Collectors; |
| 32 | |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 33 | /** |
| 34 | * Utility class for OLT app. |
| 35 | */ |
Gustavo Silva | 29fb20e | 2022-05-26 09:59:54 -0300 | [diff] [blame] | 36 | public final class OltUtils { |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 37 | |
| 38 | private OltUtils() { |
| 39 | } |
| 40 | |
| 41 | /** |
| 42 | * Returns the port name if present in the annotations. |
| 43 | * @param port the port |
| 44 | * @return the annotated port name |
| 45 | */ |
Gustavo Silva | 29fb20e | 2022-05-26 09:59:54 -0300 | [diff] [blame] | 46 | public static String getPortName(Port port) { |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 47 | String name = port.annotations().value(AnnotationKeys.PORT_NAME); |
| 48 | return name == null ? "" : name; |
| 49 | } |
| 50 | |
| 51 | /** |
| 52 | * Returns a port printed as a connect point and with the name appended. |
| 53 | * @param port the port |
| 54 | * @return the formatted string |
| 55 | */ |
Gustavo Silva | 29fb20e | 2022-05-26 09:59:54 -0300 | [diff] [blame] | 56 | public static String portWithName(Port port) { |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 57 | return port.element().id().toString() + '/' + |
| 58 | port.number() + '[' + |
| 59 | getPortName(port) + ']'; |
| 60 | } |
| 61 | |
Gustavo Silva | 29fb20e | 2022-05-26 09:59:54 -0300 | [diff] [blame] | 62 | public static String flowOpToString(FlowOperation op) { |
| 63 | return op == FlowOperation.ADD ? "Adding" : "Removing"; |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 64 | } |
| 65 | |
Gustavo Silva | 29fb20e | 2022-05-26 09:59:54 -0300 | [diff] [blame] | 66 | public static String completeFlowOpToString(FlowOperation op) { |
| 67 | return op == FlowOperation.ADD ? "Added" : "Removed"; |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 68 | } |
Harsh Awasthi | c1e4bf5 | 2022-02-09 14:14:14 +0530 | [diff] [blame] | 69 | |
| 70 | /** |
| 71 | * Search and return the matching UniTagInfomation from the list of UniTagInfomation in the |
| 72 | * SubscriberAndDeviceInformation. |
| 73 | * For the match : cvlan, svlan and tpId are used. |
| 74 | * |
| 75 | * @param subInfo Subscriber information. |
| 76 | * @param innerVlan cTag |
| 77 | * @param outerVlan sTag |
| 78 | * @param tpId Techprofile Id |
| 79 | * @return UniTagInformation |
| 80 | */ |
Gustavo Silva | 29fb20e | 2022-05-26 09:59:54 -0300 | [diff] [blame] | 81 | public static UniTagInformation getUniTagInformation(SubscriberAndDeviceInformation subInfo, VlanId innerVlan, |
Harsh Awasthi | c1e4bf5 | 2022-02-09 14:14:14 +0530 | [diff] [blame] | 82 | VlanId outerVlan, int tpId) { |
| 83 | UniTagInformation service = null; |
| 84 | for (UniTagInformation tagInfo : subInfo.uniTagList()) { |
| 85 | if (innerVlan.equals(tagInfo.getPonCTag()) && outerVlan.equals(tagInfo.getPonSTag()) |
| 86 | && tpId == tagInfo.getTechnologyProfileId()) { |
| 87 | service = tagInfo; |
| 88 | break; |
| 89 | } |
| 90 | } |
| 91 | return service; |
| 92 | } |
Gustavo Silva | 89e2f04 | 2022-08-01 09:58:04 -0300 | [diff] [blame] | 93 | |
| 94 | public static SubscriberAndDeviceInformation getProgrammedSubscriber( |
| 95 | OltFlowServiceInterface service, AccessDevicePort accessDevicePort) { |
| 96 | List<Map.Entry<ServiceKey, UniTagInformation>> entries = |
| 97 | service.getProgrammedSubscribers().entrySet().stream() |
| 98 | .filter(entry -> entry.getKey().getPort().equals(accessDevicePort)) |
| 99 | .collect(Collectors.toList()); |
| 100 | if (!entries.isEmpty()) { |
| 101 | List<UniTagInformation> programmedList = entries.stream() |
| 102 | .map(entry -> entry.getKey().getService()) |
| 103 | .collect(Collectors.toList()); |
| 104 | SubscriberAndDeviceInformation si = new SubscriberAndDeviceInformation(); |
| 105 | si.setUniTagList(programmedList); |
| 106 | return si; |
| 107 | } |
| 108 | return null; |
| 109 | } |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 110 | } |