blob: 19d27b50829cf348f493969373ec08b8c72fd02b [file] [log] [blame]
Sho SHIMIZUc15ce512015-05-26 16:54:08 -07001/*
2 * Copyright 2015 Open Networking Laboratory
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 */
16package org.onosproject.provider.of.flow.impl;
17
18import org.onosproject.net.ChannelSpacing;
19import org.onosproject.net.GridType;
Marc De Leenheerd24420f2015-05-27 09:40:59 -070020import org.onosproject.net.OchSignalType;
Sho SHIMIZUc15ce512015-05-26 16:54:08 -070021import org.slf4j.Logger;
22import org.slf4j.LoggerFactory;
23
24/**
25 * Collection of helper methods to convert protocol agnostic models to values used in OpenFlow spec.
26 */
Sho SHIMIZU4f828ee2015-05-28 09:38:21 -070027// TODO: Rename to a better name
Sho SHIMIZUc15ce512015-05-26 16:54:08 -070028final class FlowModBuilderHelper {
29
30 private static final Logger log = LoggerFactory.getLogger(FlowModBuilderHelper.class);
31
32 // prohibit instantiation
33 private FlowModBuilderHelper() {}
34
35 /**
36 * Converts a {@link GridType} to the corresponding byte value defined in
37 * ONF "Optical Transport Protocol Extensions Version 1.0".
38 *
39 * @param type grid type
40 * @return the byte value corresponding to the specified grid type
41 * @throws UnsupportedGridTypeException if the specified grid type is not supported
42 */
43 static byte convertGridType(GridType type) {
44 // See ONF "Optical Transport Protocol Extensions Version 1.0"
45 // for the following values
46 switch (type) {
47 case DWDM:
48 // OFPGRIDT_DWDM of enum ofp_grid_type
49 return 1;
50 case CWDM:
51 // OFPGRIDT_CWDM of enum ofp_grid_type
52 return 2;
53 case FLEX:
54 // OFPGRIDT_FLEX of enum ofp_grid_type
55 return 3;
56 default:
57 throw new UnsupportedGridTypeException(type);
58 }
59 }
60
61 /**
Sho SHIMIZU4f828ee2015-05-28 09:38:21 -070062 * Converts a byte value for grid type
63 * defined in ONF "Optical Transport Protocol Extensions Version 1.0"
64 * to the corresponding {@link GridType} instance.
65 *
66 * @param type byte value as grid type defined the spec
67 * @return the corresponding GridType instance
68 */
69 static GridType convertGridType(byte type) {
70 switch (type) {
71 case 1:
72 return GridType.DWDM;
73 case 2:
74 return GridType.CWDM;
75 case 3:
76 return GridType.FLEX;
77 default:
78 log.info("The value {} for grid type is not supported");
79 return null;
80 }
81 }
82
83 /**
Sho SHIMIZUc15ce512015-05-26 16:54:08 -070084 * Converts a {@link ChannelSpacing} to the corresponding byte value defined in
85 * ONF "Optical Transport Protocol Extensions Version 1.0".
86 *
87 * @param spacing channel spacing
88 * @return byte value corresponding to the specified channel spacing
89 * @throws UnsupportedChannelSpacingException if the specified channel spacing is not supported
90 */
91 static byte convertChannelSpacing(ChannelSpacing spacing) {
92 // See ONF "Optical Transport Protocol Extensions Version 1.0"
93 // for the following values
94 switch (spacing) {
95 case CHL_100GHZ:
96 // OFPCS_100GHZ of enum ofp_chl_spacing
97 return 1;
98 case CHL_50GHZ:
99 // OFPCS_50GHZ of enum ofp_chl_spacing
100 return 2;
101 case CHL_25GHZ:
102 // OFPCS_25GHZ of enum ofp_chl_spacing
103 return 3;
104 case CHL_12P5GHZ:
105 // OFPCS_12P5GHZ of enum ofp_chl_spacing
106 return 4;
107 case CHL_6P25GHZ:
108 // OFPCS_6P25GHZ of enum ofp_chl_spacing
109 return 5;
110 default:
111 throw new UnsupportedChannelSpacingException(spacing);
112 }
113 }
Marc De Leenheerd24420f2015-05-27 09:40:59 -0700114
115 /**
Sho SHIMIZU4f828ee2015-05-28 09:38:21 -0700116 * Converts a byte value for channel spacing
117 * defined in ONF "Optical Transport Protocol Extensions Version 1.0"
118 * to the corresponding {@link ChannelSpacing} instance.
119 *
120 * @param spacing byte value as channel spacing defined the spec
121 * @return the corresponding ChannelSpacing instance
122 */
123 static ChannelSpacing convertChannelSpacing(byte spacing) {
124 switch (spacing) {
125 case 1:
126 return ChannelSpacing.CHL_100GHZ;
127 case 2:
128 return ChannelSpacing.CHL_50GHZ;
129 case 3:
130 return ChannelSpacing.CHL_25GHZ;
131 case 4:
132 return ChannelSpacing.CHL_12P5GHZ;
133 case 5:
134 return ChannelSpacing.CHL_6P25GHZ;
135 default:
136 log.info("The value {} for channel spacing is not supported");
137 return null;
138 }
139 }
140
141 /**
Marc De Leenheerd24420f2015-05-27 09:40:59 -0700142 * Converts a {@link OchSignalType} to the corresponding byte value.
143 *
144 * @param signalType optical signal type
145 * @return byte value corresponding to the specified OCh signal type
146 */
147 static byte convertOchSignalType(OchSignalType signalType) {
148 switch (signalType) {
149 case FIXED_GRID:
150 return (byte) 1;
151 case FLEX_GRID:
152 return (byte) 2;
153 default:
154 log.info("OchSignalType {} is not supported", signalType);
155 return (byte) 0;
156 }
157 }
Sho SHIMIZU4f828ee2015-05-28 09:38:21 -0700158
159 /**
160 * Converts a byte value for Och signal type
161 * defined in ONF "Optical Transport Protocol Extensions Version 1.0"
162 * to the corresponding {@link OchSignalType} instance.
163 *
164 * @param signalType byte value as Och singal type defined the spec
165 * @return the corresponding OchSignalType instance
166 */
167 static OchSignalType convertOchSignalType(byte signalType) {
168 switch (signalType) {
169 case 1:
170 return OchSignalType.FIXED_GRID;
171 case 2:
172 return OchSignalType.FLEX_GRID;
173 default:
174 log.info("The value {} for Och signal type is not supported");
175 return null;
176 }
177 }
Sho SHIMIZUc15ce512015-05-26 16:54:08 -0700178}