Rimon Ashkenazy | 27438ff | 2016-03-22 15:57:45 +0200 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Laboratory |
Rimon Ashkenazy | 27438ff | 2016-03-22 15:57:45 +0200 | [diff] [blame] | 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 | */ |
| 16 | |
| 17 | package org.onosproject.net; |
| 18 | |
| 19 | import java.util.Set; |
| 20 | |
| 21 | import org.slf4j.Logger; |
| 22 | import org.slf4j.LoggerFactory; |
| 23 | |
| 24 | /** |
| 25 | * Collection of helper methods to convert various SignalTypes to OduSignalType, and to build OduSignalId. |
| 26 | */ |
| 27 | public 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 | } |