blob: b5f0f4800c0df1724c7134211d7e693267f00dd7 [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;
21import org.onosproject.net.Port;
22import org.onosproject.net.PortNumber;
23import org.onosproject.net.TributarySlot;
24import org.onosproject.net.device.DeviceService;
25import org.onosproject.net.driver.AbstractHandlerBehaviour;
26import org.onosproject.net.behaviour.TributarySlotQuery;
27import org.slf4j.Logger;
28import org.slf4j.LoggerFactory;
29
30import java.util.Collections;
31import java.util.Set;
32import java.util.stream.IntStream;
33
34/**
35 * TributarySlotQuery implementation which responds that all slots of ODU2 or ODU4 are available for the port.
36 */
37public class DefaultTributarySlotQuery extends AbstractHandlerBehaviour implements TributarySlotQuery {
38
39 private static final Logger log = LoggerFactory.getLogger(DefaultTributarySlotQuery.class);
40
41 private static final int TOTAL_ODU2_TRIBUTARY_SLOTS = 8;
42 private static final int TOTAL_ODU4_TRIBUTARY_SLOTS = 80;
43
44 private static Set<TributarySlot> getEntireOdu2TributarySlots() {
45 return IntStream.rangeClosed(1, TOTAL_ODU2_TRIBUTARY_SLOTS)
46 .mapToObj(TributarySlot::of)
47 .collect(GuavaCollectors.toImmutableSet());
48 }
49
50 private static Set<TributarySlot> getEntireOdu4TributarySlots() {
51 return IntStream.rangeClosed(1, TOTAL_ODU4_TRIBUTARY_SLOTS)
52 .mapToObj(TributarySlot::of)
53 .collect(GuavaCollectors.toImmutableSet());
54 }
55
56 private static final Set<TributarySlot> ENTIRE_ODU2_TRIBUTARY_SLOTS = getEntireOdu2TributarySlots();
57 private static final Set<TributarySlot> ENTIRE_ODU4_TRIBUTARY_SLOTS = getEntireOdu4TributarySlots();
58
59 @Override
60 public Set<TributarySlot> queryTributarySlots(PortNumber port) {
61 // currently return all slots by default.
62 DeviceService deviceService = this.handler().get(DeviceService.class);
63 Port p = deviceService.getPort(this.data().deviceId(), port);
64
65 if (!(p instanceof OchPort)) {
66 return Collections.emptySet();
67 }
68 OduSignalType signalType = ((OchPort) p).signalType();
69 switch (signalType) {
70 case ODU2:
71 return ENTIRE_ODU2_TRIBUTARY_SLOTS;
72 case ODU4:
73 return ENTIRE_ODU4_TRIBUTARY_SLOTS;
74 default:
75 log.error("Unsupported signal type {}", signalType);
76 return Collections.emptySet();
77 }
78 }
79}