blob: ab9d4942461818fa76f4208c7768f2a277d43402 [file] [log] [blame]
HIGUCHI Yutab7a15d72015-12-15 09:54:40 -08001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2016-present Open Networking Laboratory
HIGUCHI Yutab7a15d72015-12-15 09:54:40 -08003 *
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
Sho SHIMIZU55caa1c2016-05-18 23:35:02 -070021import com.google.common.collect.ImmutableSet;
HIGUCHI Yutab7a15d72015-12-15 09:54:40 -080022import org.onlab.packet.VlanId;
23import org.onlab.util.GuavaCollectors;
24import org.onosproject.net.PortNumber;
25import org.onosproject.net.behaviour.VlanQuery;
26import org.onosproject.net.driver.AbstractHandlerBehaviour;
27
28import com.google.common.annotations.Beta;
29
30/**
31 * Driver which always responds that all VLAN IDs are available for the Device.
32 */
33@Beta
34public class FullVlanAvailable
35 extends AbstractHandlerBehaviour
36 implements VlanQuery {
37
38 private static final int MAX_VLAN_ID = VlanId.MAX_VLAN;
Sho SHIMIZU55caa1c2016-05-18 23:35:02 -070039 private static final Set<Integer> EXCLUDED = ImmutableSet.of(
40 (int) VlanId.NO_VID,
41 (int) VlanId.RESERVED);
Thomas Vachuskaab0bded2016-05-20 12:11:09 -070042 private static final Set<VlanId> ENTIRE_VLAN = getEntireVlans();
HIGUCHI Yutab7a15d72015-12-15 09:54:40 -080043
44 @Override
45 public Set<VlanId> queryVlanIds(PortNumber port) {
46 return ENTIRE_VLAN;
47 }
48
49 private static Set<VlanId> getEntireVlans() {
50 return IntStream.range(0, MAX_VLAN_ID)
Sho SHIMIZU55caa1c2016-05-18 23:35:02 -070051 .filter(x -> !EXCLUDED.contains(x))
HIGUCHI Yutab7a15d72015-12-15 09:54:40 -080052 .mapToObj(x -> VlanId.vlanId((short) x))
53 .collect(GuavaCollectors.toImmutableSet());
54 }
55
56}