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 | |
Sho SHIMIZU | 55caa1c | 2016-05-18 23:35:02 -0700 | [diff] [blame] | 21 | import com.google.common.collect.ImmutableSet; |
HIGUCHI Yuta | b7a15d7 | 2015-12-15 09:54:40 -0800 | [diff] [blame] | 22 | import org.onlab.packet.VlanId; |
HIGUCHI Yuta | b7a15d7 | 2015-12-15 09:54:40 -0800 | [diff] [blame] | 23 | import org.onosproject.net.PortNumber; |
| 24 | import org.onosproject.net.behaviour.VlanQuery; |
| 25 | import org.onosproject.net.driver.AbstractHandlerBehaviour; |
| 26 | |
| 27 | import com.google.common.annotations.Beta; |
| 28 | |
| 29 | /** |
| 30 | * Driver which always responds that all VLAN IDs are available for the Device. |
| 31 | */ |
| 32 | @Beta |
| 33 | public class FullVlanAvailable |
| 34 | extends AbstractHandlerBehaviour |
| 35 | implements VlanQuery { |
| 36 | |
| 37 | private static final int MAX_VLAN_ID = VlanId.MAX_VLAN; |
Sho SHIMIZU | 55caa1c | 2016-05-18 23:35:02 -0700 | [diff] [blame] | 38 | private static final Set<Integer> EXCLUDED = ImmutableSet.of( |
| 39 | (int) VlanId.NO_VID, |
| 40 | (int) VlanId.RESERVED); |
Thomas Vachuska | ab0bded | 2016-05-20 12:11:09 -0700 | [diff] [blame] | 41 | private static final Set<VlanId> ENTIRE_VLAN = getEntireVlans(); |
HIGUCHI Yuta | b7a15d7 | 2015-12-15 09:54:40 -0800 | [diff] [blame] | 42 | |
| 43 | @Override |
| 44 | public Set<VlanId> queryVlanIds(PortNumber port) { |
| 45 | return ENTIRE_VLAN; |
| 46 | } |
| 47 | |
| 48 | private static Set<VlanId> getEntireVlans() { |
| 49 | return IntStream.range(0, MAX_VLAN_ID) |
Sho SHIMIZU | 55caa1c | 2016-05-18 23:35:02 -0700 | [diff] [blame] | 50 | .filter(x -> !EXCLUDED.contains(x)) |
HIGUCHI Yuta | b7a15d7 | 2015-12-15 09:54:40 -0800 | [diff] [blame] | 51 | .mapToObj(x -> VlanId.vlanId((short) x)) |
Yuta HIGUCHI | 498fa1d | 2017-05-17 16:08:40 -0700 | [diff] [blame] | 52 | .collect(ImmutableSet.toImmutableSet()); |
HIGUCHI Yuta | b7a15d7 | 2015-12-15 09:54:40 -0800 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | } |