HIGUCHI Yuta | b7a15d7 | 2015-12-15 09:54:40 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Laboratory |
HIGUCHI Yuta | b7a15d7 | 2015-12-15 09:54:40 -0800 | [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 | package org.onosproject.driver.query; |
| 17 | |
| 18 | import java.util.Set; |
| 19 | import java.util.stream.IntStream; |
| 20 | |
| 21 | import org.onlab.packet.MplsLabel; |
| 22 | import org.onlab.util.GuavaCollectors; |
| 23 | import org.onosproject.net.PortNumber; |
| 24 | import org.onosproject.net.behaviour.MplsQuery; |
| 25 | import org.onosproject.net.driver.AbstractHandlerBehaviour; |
| 26 | |
| 27 | /** |
| 28 | * Driver which always responds that all MPLS Labels are available for the Device. |
| 29 | */ |
| 30 | public 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 | } |