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 | 29fb20e | 2022-05-26 09:59:54 -0300 | [diff] [blame] | 22 | import org.opencord.olt.FlowOperation; |
Harsh Awasthi | c1e4bf5 | 2022-02-09 14:14:14 +0530 | [diff] [blame] | 23 | import org.opencord.sadis.SubscriberAndDeviceInformation; |
| 24 | import org.opencord.sadis.UniTagInformation; |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 25 | |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 26 | /** |
| 27 | * Utility class for OLT app. |
| 28 | */ |
Gustavo Silva | 29fb20e | 2022-05-26 09:59:54 -0300 | [diff] [blame] | 29 | public final class OltUtils { |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 30 | |
| 31 | private OltUtils() { |
| 32 | } |
| 33 | |
| 34 | /** |
| 35 | * Returns the port name if present in the annotations. |
| 36 | * @param port the port |
| 37 | * @return the annotated port name |
| 38 | */ |
Gustavo Silva | 29fb20e | 2022-05-26 09:59:54 -0300 | [diff] [blame] | 39 | public static String getPortName(Port port) { |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 40 | String name = port.annotations().value(AnnotationKeys.PORT_NAME); |
| 41 | return name == null ? "" : name; |
| 42 | } |
| 43 | |
| 44 | /** |
| 45 | * Returns a port printed as a connect point and with the name appended. |
| 46 | * @param port the port |
| 47 | * @return the formatted string |
| 48 | */ |
Gustavo Silva | 29fb20e | 2022-05-26 09:59:54 -0300 | [diff] [blame] | 49 | public static String portWithName(Port port) { |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 50 | return port.element().id().toString() + '/' + |
| 51 | port.number() + '[' + |
| 52 | getPortName(port) + ']'; |
| 53 | } |
| 54 | |
Gustavo Silva | 29fb20e | 2022-05-26 09:59:54 -0300 | [diff] [blame] | 55 | public static String flowOpToString(FlowOperation op) { |
| 56 | return op == FlowOperation.ADD ? "Adding" : "Removing"; |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 57 | } |
| 58 | |
Gustavo Silva | 29fb20e | 2022-05-26 09:59:54 -0300 | [diff] [blame] | 59 | public static String completeFlowOpToString(FlowOperation op) { |
| 60 | return op == FlowOperation.ADD ? "Added" : "Removed"; |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 61 | } |
Harsh Awasthi | c1e4bf5 | 2022-02-09 14:14:14 +0530 | [diff] [blame] | 62 | |
| 63 | /** |
| 64 | * Search and return the matching UniTagInfomation from the list of UniTagInfomation in the |
| 65 | * SubscriberAndDeviceInformation. |
| 66 | * For the match : cvlan, svlan and tpId are used. |
| 67 | * |
| 68 | * @param subInfo Subscriber information. |
| 69 | * @param innerVlan cTag |
| 70 | * @param outerVlan sTag |
| 71 | * @param tpId Techprofile Id |
| 72 | * @return UniTagInformation |
| 73 | */ |
Gustavo Silva | 29fb20e | 2022-05-26 09:59:54 -0300 | [diff] [blame] | 74 | public static UniTagInformation getUniTagInformation(SubscriberAndDeviceInformation subInfo, VlanId innerVlan, |
Harsh Awasthi | c1e4bf5 | 2022-02-09 14:14:14 +0530 | [diff] [blame] | 75 | VlanId outerVlan, int tpId) { |
| 76 | UniTagInformation service = null; |
| 77 | for (UniTagInformation tagInfo : subInfo.uniTagList()) { |
| 78 | if (innerVlan.equals(tagInfo.getPonCTag()) && outerVlan.equals(tagInfo.getPonSTag()) |
| 79 | && tpId == tagInfo.getTechnologyProfileId()) { |
| 80 | service = tagInfo; |
| 81 | break; |
| 82 | } |
| 83 | } |
| 84 | return service; |
| 85 | } |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 86 | } |