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