blob: f85e0db614ad446e97d8bf131b66f6007ab0dac7 [file] [log] [blame]
Toru Furusawac23f5832015-12-04 11:39:18 -08001/*
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.driver.query;
17
18import org.onlab.util.GuavaCollectors;
19import org.onosproject.net.OchPort;
20import org.onosproject.net.OduSignalType;
Rimon Ashkenazy9ab0dc42016-02-22 18:22:57 +020021import org.onosproject.net.OtuPort;
22import org.onosproject.net.OtuSignalType;
Toru Furusawac23f5832015-12-04 11:39:18 -080023import org.onosproject.net.Port;
24import org.onosproject.net.PortNumber;
25import org.onosproject.net.TributarySlot;
26import org.onosproject.net.device.DeviceService;
27import org.onosproject.net.driver.AbstractHandlerBehaviour;
28import org.onosproject.net.behaviour.TributarySlotQuery;
29import org.slf4j.Logger;
30import org.slf4j.LoggerFactory;
31
32import java.util.Collections;
33import java.util.Set;
34import java.util.stream.IntStream;
35
36/**
37 * TributarySlotQuery implementation which responds that all slots of ODU2 or ODU4 are available for the port.
38 */
39public class DefaultTributarySlotQuery extends AbstractHandlerBehaviour implements TributarySlotQuery {
40
41 private static final Logger log = LoggerFactory.getLogger(DefaultTributarySlotQuery.class);
42
43 private static final int TOTAL_ODU2_TRIBUTARY_SLOTS = 8;
44 private static final int TOTAL_ODU4_TRIBUTARY_SLOTS = 80;
45
46 private static Set<TributarySlot> getEntireOdu2TributarySlots() {
47 return IntStream.rangeClosed(1, TOTAL_ODU2_TRIBUTARY_SLOTS)
48 .mapToObj(TributarySlot::of)
49 .collect(GuavaCollectors.toImmutableSet());
50 }
51
52 private static Set<TributarySlot> getEntireOdu4TributarySlots() {
53 return IntStream.rangeClosed(1, TOTAL_ODU4_TRIBUTARY_SLOTS)
54 .mapToObj(TributarySlot::of)
55 .collect(GuavaCollectors.toImmutableSet());
56 }
57
58 private static final Set<TributarySlot> ENTIRE_ODU2_TRIBUTARY_SLOTS = getEntireOdu2TributarySlots();
59 private static final Set<TributarySlot> ENTIRE_ODU4_TRIBUTARY_SLOTS = getEntireOdu4TributarySlots();
60
61 @Override
62 public Set<TributarySlot> queryTributarySlots(PortNumber port) {
63 // currently return all slots by default.
64 DeviceService deviceService = this.handler().get(DeviceService.class);
65 Port p = deviceService.getPort(this.data().deviceId(), port);
66
Rimon Ashkenazy9ab0dc42016-02-22 18:22:57 +020067 switch (p.type()) {
68 case OCH:
69 return queryOchTributarySlots((OchPort) p);
70 case OTU:
71 return queryOtuTributarySlots((OtuPort) p);
72 default:
73 return Collections.emptySet();
Toru Furusawac23f5832015-12-04 11:39:18 -080074 }
Rimon Ashkenazy9ab0dc42016-02-22 18:22:57 +020075 }
76
77 private Set<TributarySlot> queryOchTributarySlots(OchPort ochPort) {
78 OduSignalType signalType = ochPort.signalType();
Toru Furusawac23f5832015-12-04 11:39:18 -080079 switch (signalType) {
80 case ODU2:
81 return ENTIRE_ODU2_TRIBUTARY_SLOTS;
82 case ODU4:
83 return ENTIRE_ODU4_TRIBUTARY_SLOTS;
84 default:
Rimon Ashkenazy9ab0dc42016-02-22 18:22:57 +020085 log.error("Unsupported signal type {} for {}", signalType, ochPort);
86 return Collections.emptySet();
87 }
88 }
89
90 private Set<TributarySlot> queryOtuTributarySlots(OtuPort otuPort) {
91 OtuSignalType signalType = otuPort.signalType();
92 switch (signalType) {
93 case OTU2:
94 return ENTIRE_ODU2_TRIBUTARY_SLOTS;
95 case OTU4:
96 return ENTIRE_ODU4_TRIBUTARY_SLOTS;
97 default:
98 log.error("Unsupported signal type {} for {}", signalType, otuPort);
Toru Furusawac23f5832015-12-04 11:39:18 -080099 return Collections.emptySet();
100 }
101 }
102}