blob: ca2f45cad3add4a97d07a7bb124e0f5e976343cd [file] [log] [blame]
Rimon Ashkenazy27438ff2016-03-22 15:57:45 +02001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2016-present Open Networking Laboratory
Rimon Ashkenazy27438ff2016-03-22 15:57:45 +02003 *
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.onosproject.net;
18
19import java.util.Set;
20
21import org.slf4j.Logger;
22import org.slf4j.LoggerFactory;
23
24/**
25 * Collection of helper methods to convert various SignalTypes to OduSignalType, and to build OduSignalId.
26 */
27public final class OduSignalUtils {
28
29 private static final Logger log = LoggerFactory.getLogger(OduSignalUtils.class);
30
31 // prohibit instantiation
32 private OduSignalUtils() {}
33
34 /**
35 * Maps from OduClt SignalType to OduSignalType.
36 *
37 * @param cltSignalType OduClt port signal type
38 * @return OduSignalType the result of mapping CltSignalType to OduSignalType
39 */
40 public static OduSignalType mappingCltSignalTypeToOduSignalType(CltSignalType cltSignalType) {
41 switch (cltSignalType) {
42 case CLT_1GBE:
43 return OduSignalType.ODU0;
44 case CLT_10GBE:
45 return OduSignalType.ODU2;
46 case CLT_40GBE:
47 return OduSignalType.ODU3;
48 case CLT_100GBE:
49 return OduSignalType.ODU4;
50 default:
51 log.error("Unsupported CltSignalType {}", cltSignalType);
52 return OduSignalType.ODU0;
53 }
54 }
55
56 /**
57 * Maps from OtuPort SignalType to OduSignalType.
58 *
59 * @param otuSignalType Otu port signal type
60 * @return OduSignalType the result of mapping OtuSignalType to OduSignalType
61 */
62 public static OduSignalType mappingOtuSignalTypeToOduSignalType(OtuSignalType otuSignalType) {
63 switch (otuSignalType) {
64 case OTU2:
65 return OduSignalType.ODU2;
66 case OTU4:
67 return OduSignalType.ODU4;
68 default:
69 log.error("Unsupported OtuSignalType {}", otuSignalType);
70 return OduSignalType.ODU0;
71 }
72 }
73
74 /**
75 * Creates OduSignalId from OduSignalType and TributarySlots.
76 * @param oduSignalType - OduSignalType
77 * @param slots - a set of TributarySlots
78 * @return OduSignalId
79 */
80 public static OduSignalId buildOduSignalId(OduSignalType oduSignalType, Set<TributarySlot> slots) {
81 int tributaryPortNumber = (int) slots.stream().findFirst().get().index();
82 int tributarySlotLen = oduSignalType.tributarySlots();
83 byte[] tributarySlotBitmap = new byte[OduSignalId.TRIBUTARY_SLOT_BITMAP_SIZE];
84
85 slots.forEach(ts -> tributarySlotBitmap[(byte) (ts.index() - 1) / 8] |= 0x1 << ((ts.index() - 1) % 8));
86 return OduSignalId.oduSignalId(tributaryPortNumber, tributarySlotLen, tributarySlotBitmap);
87 }
88
89}