blob: fd9cac4199971dba54cc9a120e4bee3bc860cc0b [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;
20import org.slf4j.Logger;
21import org.slf4j.LoggerFactory;
22
23/**
24 * Collection of helper methods to convert protocol agnostic models to values used in OpenFlow spec.
25 */
26final class FlowModBuilderHelper {
27
28 private static final Logger log = LoggerFactory.getLogger(FlowModBuilderHelper.class);
29
30 // prohibit instantiation
31 private FlowModBuilderHelper() {}
32
33 /**
34 * Converts a {@link GridType} to the corresponding byte value defined in
35 * ONF "Optical Transport Protocol Extensions Version 1.0".
36 *
37 * @param type grid type
38 * @return the byte value corresponding to the specified grid type
39 * @throws UnsupportedGridTypeException if the specified grid type is not supported
40 */
41 static byte convertGridType(GridType type) {
42 // See ONF "Optical Transport Protocol Extensions Version 1.0"
43 // for the following values
44 switch (type) {
45 case DWDM:
46 // OFPGRIDT_DWDM of enum ofp_grid_type
47 return 1;
48 case CWDM:
49 // OFPGRIDT_CWDM of enum ofp_grid_type
50 return 2;
51 case FLEX:
52 // OFPGRIDT_FLEX of enum ofp_grid_type
53 return 3;
54 default:
55 throw new UnsupportedGridTypeException(type);
56 }
57 }
58
59 /**
60 * Converts a {@link ChannelSpacing} to the corresponding byte value defined in
61 * ONF "Optical Transport Protocol Extensions Version 1.0".
62 *
63 * @param spacing channel spacing
64 * @return byte value corresponding to the specified channel spacing
65 * @throws UnsupportedChannelSpacingException if the specified channel spacing is not supported
66 */
67 static byte convertChannelSpacing(ChannelSpacing spacing) {
68 // See ONF "Optical Transport Protocol Extensions Version 1.0"
69 // for the following values
70 switch (spacing) {
71 case CHL_100GHZ:
72 // OFPCS_100GHZ of enum ofp_chl_spacing
73 return 1;
74 case CHL_50GHZ:
75 // OFPCS_50GHZ of enum ofp_chl_spacing
76 return 2;
77 case CHL_25GHZ:
78 // OFPCS_25GHZ of enum ofp_chl_spacing
79 return 3;
80 case CHL_12P5GHZ:
81 // OFPCS_12P5GHZ of enum ofp_chl_spacing
82 return 4;
83 case CHL_6P25GHZ:
84 // OFPCS_6P25GHZ of enum ofp_chl_spacing
85 return 5;
86 default:
87 throw new UnsupportedChannelSpacingException(spacing);
88 }
89 }
90}