blob: efe1912ad0459cda64232684f8020e6137d1ff60 [file] [log] [blame]
HIGUCHI Yutab7a15d72015-12-15 09:54:40 -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 java.util.Set;
19import java.util.stream.IntStream;
20
21import org.onlab.packet.MplsLabel;
22import org.onlab.util.GuavaCollectors;
23import org.onosproject.net.PortNumber;
24import org.onosproject.net.behaviour.MplsQuery;
25import org.onosproject.net.driver.AbstractHandlerBehaviour;
26
27/**
28 * Driver which always responds that all MPLS Labels are available for the Device.
29 */
30public class FullMplsAvailable
31 extends AbstractHandlerBehaviour
32 implements MplsQuery {
33
34 // Ref: http://www.iana.org/assignments/mpls-label-values/mpls-label-values.xhtml
35 // Smallest non-reserved MPLS label
36 private static final int MIN_UNRESERVED_LABEL = 0x10;
37 // Max non-reserved MPLS label = 239
38 private static final int MAX_UNRESERVED_LABEL = 0xEF;
39 private static final Set<MplsLabel> ENTIRE_MPLS_LABELS = getEntireMplsLabels();
40
41
42 @Override
43 public Set<MplsLabel> queryMplsLabels(PortNumber port) {
44 return ENTIRE_MPLS_LABELS;
45 }
46
47 private static Set<MplsLabel> getEntireMplsLabels() {
48 return IntStream.range(MIN_UNRESERVED_LABEL, MAX_UNRESERVED_LABEL + 1)
49 .mapToObj(MplsLabel::mplsLabel)
50 .collect(GuavaCollectors.toImmutableSet());
51 }
52
53}