blob: 81ee133543f8320cb08db179eb513434c34ed256 [file] [log] [blame]
Matteo Scandoloaa2adde2021-09-13 12:45:32 -07001/*
Joey Armstrong7f6d6d22023-01-09 17:09:50 -05002 * Copyright 2021-2023 Open Networking Foundation (ONF) and the ONF Contributors
Matteo Scandoloaa2adde2021-09-13 12:45:32 -07003 *
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
17package org.opencord.olt.impl;
18
Harsh Awasthic1e4bf52022-02-09 14:14:14 +053019import org.onlab.packet.VlanId;
Matteo Scandoloaa2adde2021-09-13 12:45:32 -070020import org.onosproject.net.AnnotationKeys;
21import org.onosproject.net.Port;
Gustavo Silva29fb20e2022-05-26 09:59:54 -030022import org.opencord.olt.FlowOperation;
Harsh Awasthic1e4bf52022-02-09 14:14:14 +053023import org.opencord.sadis.SubscriberAndDeviceInformation;
24import org.opencord.sadis.UniTagInformation;
Matteo Scandoloaa2adde2021-09-13 12:45:32 -070025
Matteo Scandoloaa2adde2021-09-13 12:45:32 -070026/**
27 * Utility class for OLT app.
28 */
Gustavo Silva29fb20e2022-05-26 09:59:54 -030029public final class OltUtils {
Matteo Scandoloaa2adde2021-09-13 12:45:32 -070030
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 Silva29fb20e2022-05-26 09:59:54 -030039 public static String getPortName(Port port) {
Matteo Scandoloaa2adde2021-09-13 12:45:32 -070040 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 Silva29fb20e2022-05-26 09:59:54 -030049 public static String portWithName(Port port) {
Matteo Scandoloaa2adde2021-09-13 12:45:32 -070050 return port.element().id().toString() + '/' +
51 port.number() + '[' +
52 getPortName(port) + ']';
53 }
54
Gustavo Silva29fb20e2022-05-26 09:59:54 -030055 public static String flowOpToString(FlowOperation op) {
56 return op == FlowOperation.ADD ? "Adding" : "Removing";
Matteo Scandoloaa2adde2021-09-13 12:45:32 -070057 }
58
Gustavo Silva29fb20e2022-05-26 09:59:54 -030059 public static String completeFlowOpToString(FlowOperation op) {
60 return op == FlowOperation.ADD ? "Added" : "Removed";
Matteo Scandoloaa2adde2021-09-13 12:45:32 -070061 }
Harsh Awasthic1e4bf52022-02-09 14:14:14 +053062
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 Silva29fb20e2022-05-26 09:59:54 -030074 public static UniTagInformation getUniTagInformation(SubscriberAndDeviceInformation subInfo, VlanId innerVlan,
Harsh Awasthic1e4bf52022-02-09 14:14:14 +053075 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 Scandoloaa2adde2021-09-13 12:45:32 -070086}