blob: 6300ff9601a109f1e06fab009a1215d08330fc1f [file] [log] [blame]
Matteo Scandoloaa2adde2021-09-13 12:45:32 -07001/*
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
17package org.opencord.olt.impl;
18
19import org.onosproject.net.AnnotationKeys;
20import org.onosproject.net.Port;
21
22import static org.opencord.olt.impl.OltFlowService.FlowOperation.ADD;
23
24/**
25 * Utility class for OLT app.
26 */
27final class OltUtils {
28
29 private OltUtils() {
30 }
31
32 /**
33 * Returns the port name if present in the annotations.
34 * @param port the port
35 * @return the annotated port name
36 */
37 static String getPortName(Port port) {
38 String name = port.annotations().value(AnnotationKeys.PORT_NAME);
39 return name == null ? "" : name;
40 }
41
42 /**
43 * Returns a port printed as a connect point and with the name appended.
44 * @param port the port
45 * @return the formatted string
46 */
47 static String portWithName(Port port) {
48 return port.element().id().toString() + '/' +
49 port.number() + '[' +
50 getPortName(port) + ']';
51 }
52
53 static String flowOpToString(OltFlowService.FlowOperation op) {
54 return op == ADD ? "Adding" : "Removing";
55 }
56
57 static String completeFlowOpToString(OltFlowService.FlowOperation op) {
58 return op == ADD ? "Added" : "Removed";
59 }
60}