blob: c873d849c4aa7bd57bf5cbf5c84bcdf118ea75fb [file] [log] [blame]
Ayaka Koshibe2cfc65c2015-07-29 22:46:54 -07001package org.onosproject.incubator.net.config.basics;
2
3import java.util.Optional;
4
Ray Milkeya4122362015-08-18 15:19:08 -07005import org.onosproject.net.config.Config;
Ayaka Koshibe2cfc65c2015-07-29 22:46:54 -07006import org.onosproject.net.ConnectPoint;
7import org.onosproject.net.Port;
8
9import com.fasterxml.jackson.databind.JsonNode;
10
11
12/**
13 * Configurations for an optical port on a device.
14 */
15public class OpticalPortConfig extends Config<ConnectPoint> {
16 // optical type {OMS, OCH, ODUClt, fiber}
17 public static final String TYPE = "type";
18
19 // port name. "name" is the alphanumeric name of the port, but "port" refers
20 // to the port number used as a name string (i.e., for ports without
Ayaka Koshibee39c23a2015-08-03 18:17:43 -070021 // alphanumeric names).
Ayaka Koshibe2cfc65c2015-07-29 22:46:54 -070022 public static final String NAME = "name";
23 public static final String PORT = "port";
Ayaka Koshibee39c23a2015-08-03 18:17:43 -070024 public static final String STATIC_PORT = "staticPort";
25 public static final String STATIC_LAMBDA = "staticLambda";
Ayaka Koshibe2cfc65c2015-07-29 22:46:54 -070026
27 /**
28 * Returns the Enum value representing the type of port.
29 *
30 * @return the port type, or null if invalid or unset
31 */
32 public Port.Type type() {
33 JsonNode type = node.path(TYPE);
34 if (type.isMissingNode()) {
35 return null;
36 }
37 return Port.Type.valueOf(type.asText());
38 }
39
40 /**
41 * Returns the port name associated with this port configuration. The Name
Ayaka Koshibee39c23a2015-08-03 18:17:43 -070042 * is an alphanumeric string.
Ayaka Koshibe2cfc65c2015-07-29 22:46:54 -070043 *
44 * @return the name of this port, else, an empty string
45 */
46 public String name() {
Ayaka Koshibee39c23a2015-08-03 18:17:43 -070047 return getStringValue(NAME);
48 }
49
50 /**
51 * Returns a stringified representation of the port number, configured in
52 * some port types without an alphanumeric name as the port name.
53 *
54 * @return A string representation of the port number
55 */
56 public String numberName() {
57 return getStringValue(PORT);
Ayaka Koshibe2cfc65c2015-07-29 22:46:54 -070058 }
59
60 /**
61 * Returns the string-representation of name of the output port. This is
62 * usually an OMS port for an OCH input ports, or an OCH port for ODU input
63 * ports.
64 *
65 * @return the name of this port, else, an empty string
66 */
67 public String staticPort() {
Ayaka Koshibee39c23a2015-08-03 18:17:43 -070068 return getStringValue(STATIC_PORT);
Ayaka Koshibe2cfc65c2015-07-29 22:46:54 -070069 }
70
71 private String getStringValue(String field) {
72 JsonNode name = node.path(field);
73 return name.isMissingNode() ? "" : name.asText();
74 }
75
76 /**
77 * Returns the output lambda configured for this port. The lambda value is
78 * expressed as a frequency value.
79 *
80 * @return an Optional that may contain a frequency value.
81 */
82 public Optional<Long> staticLambda() {
Ayaka Koshibee39c23a2015-08-03 18:17:43 -070083 JsonNode sl = node.path(STATIC_LAMBDA);
Ayaka Koshibe2cfc65c2015-07-29 22:46:54 -070084 if (sl.isMissingNode()) {
85 return Optional.empty();
86 }
87 return Optional.of(sl.asLong());
88 }
89
90 /**
91 * Sets the port type, or updates it if it's already set. A null argument removes
92 * this field.
93 *
94 * @param type the port type
95 * @return this OpticalPortConfig instance
96 */
97 public OpticalPortConfig portType(Port.Type type) {
98 // if unspecified, ideally fall back on FIBER or PACKET.
99 String pt = (type == null) ? null : type.toString();
100 return (OpticalPortConfig) setOrClear(TYPE, pt);
101 }
102
103 /**
104 * Sets the port name, or updates it if already set. A null argument removes
105 * this field.
106 *
107 * @param name the port's name
108 * @return this OpticalPortConfig instance
109 */
110 public OpticalPortConfig portName(String name) {
111 return (OpticalPortConfig) setOrClear(NAME, name);
112 }
113
114 /**
115 * Sets the port name from port number, or updates it if already set. A null
116 * argument removes this field.
117 *
118 * @param name the port number, to be used as name
119 * @return this OpticalPortConfig instance
120 */
121 public OpticalPortConfig portNumberName(Long name) {
122 return (OpticalPortConfig) setOrClear(PORT, name);
123 }
124
125 /**
126 * Sets the output port name, or updates it if already set. A null argument
127 * removes this field.
128 *
129 * @param name the output port's name
130 * @return this OpticalPortConfig instance
131 */
132 public OpticalPortConfig staticPort(String name) {
Ayaka Koshibee39c23a2015-08-03 18:17:43 -0700133 return (OpticalPortConfig) setOrClear(STATIC_PORT, name);
Ayaka Koshibe2cfc65c2015-07-29 22:46:54 -0700134 }
135
136 /**
137 * Sets the output lambda index, or updates it if already set. A null argument
138 * removes this field.
139 *
140 * @param index the output lambda
141 * @return this OpticalPortConfig instance
142 */
143 public OpticalPortConfig staticLambda(Long index) {
Ayaka Koshibee39c23a2015-08-03 18:17:43 -0700144 return (OpticalPortConfig) setOrClear(STATIC_LAMBDA, index);
Ayaka Koshibe2cfc65c2015-07-29 22:46:54 -0700145 }
146
147}