blob: 5baba8fc6cef7e67628ce6290805df23dfa2fe86 [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 */
27final class FlowModBuilderHelper {
28
29 private static final Logger log = LoggerFactory.getLogger(FlowModBuilderHelper.class);
30
31 // prohibit instantiation
32 private FlowModBuilderHelper() {}
33
34 /**
35 * Converts a {@link GridType} to the corresponding byte value defined in
36 * ONF "Optical Transport Protocol Extensions Version 1.0".
37 *
38 * @param type grid type
39 * @return the byte value corresponding to the specified grid type
40 * @throws UnsupportedGridTypeException if the specified grid type is not supported
41 */
42 static byte convertGridType(GridType type) {
43 // See ONF "Optical Transport Protocol Extensions Version 1.0"
44 // for the following values
45 switch (type) {
46 case DWDM:
47 // OFPGRIDT_DWDM of enum ofp_grid_type
48 return 1;
49 case CWDM:
50 // OFPGRIDT_CWDM of enum ofp_grid_type
51 return 2;
52 case FLEX:
53 // OFPGRIDT_FLEX of enum ofp_grid_type
54 return 3;
55 default:
56 throw new UnsupportedGridTypeException(type);
57 }
58 }
59
60 /**
61 * Converts a {@link ChannelSpacing} to the corresponding byte value defined in
62 * ONF "Optical Transport Protocol Extensions Version 1.0".
63 *
64 * @param spacing channel spacing
65 * @return byte value corresponding to the specified channel spacing
66 * @throws UnsupportedChannelSpacingException if the specified channel spacing is not supported
67 */
68 static byte convertChannelSpacing(ChannelSpacing spacing) {
69 // See ONF "Optical Transport Protocol Extensions Version 1.0"
70 // for the following values
71 switch (spacing) {
72 case CHL_100GHZ:
73 // OFPCS_100GHZ of enum ofp_chl_spacing
74 return 1;
75 case CHL_50GHZ:
76 // OFPCS_50GHZ of enum ofp_chl_spacing
77 return 2;
78 case CHL_25GHZ:
79 // OFPCS_25GHZ of enum ofp_chl_spacing
80 return 3;
81 case CHL_12P5GHZ:
82 // OFPCS_12P5GHZ of enum ofp_chl_spacing
83 return 4;
84 case CHL_6P25GHZ:
85 // OFPCS_6P25GHZ of enum ofp_chl_spacing
86 return 5;
87 default:
88 throw new UnsupportedChannelSpacingException(spacing);
89 }
90 }
Marc De Leenheerd24420f2015-05-27 09:40:59 -070091
92 /**
93 * Converts a {@link OchSignalType} to the corresponding byte value.
94 *
95 * @param signalType optical signal type
96 * @return byte value corresponding to the specified OCh signal type
97 */
98 static byte convertOchSignalType(OchSignalType signalType) {
99 switch (signalType) {
100 case FIXED_GRID:
101 return (byte) 1;
102 case FLEX_GRID:
103 return (byte) 2;
104 default:
105 log.info("OchSignalType {} is not supported", signalType);
106 return (byte) 0;
107 }
108 }
Sho SHIMIZUc15ce512015-05-26 16:54:08 -0700109}