blob: 3664077cc93af486faec3374ef2b2281ffda18f9 [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;
HIGUCHI Yutab7a15d72015-12-15 09:54:40 -080023import org.onosproject.net.PortNumber;
24import org.onosproject.net.behaviour.VlanQuery;
25import org.onosproject.net.driver.AbstractHandlerBehaviour;
26
27import com.google.common.annotations.Beta;
28
29/**
30 * Driver which always responds that all VLAN IDs are available for the Device.
31 */
32@Beta
33public class FullVlanAvailable
34 extends AbstractHandlerBehaviour
35 implements VlanQuery {
36
37 private static final int MAX_VLAN_ID = VlanId.MAX_VLAN;
Sho SHIMIZU55caa1c2016-05-18 23:35:02 -070038 private static final Set<Integer> EXCLUDED = ImmutableSet.of(
39 (int) VlanId.NO_VID,
40 (int) VlanId.RESERVED);
Thomas Vachuskaab0bded2016-05-20 12:11:09 -070041 private static final Set<VlanId> ENTIRE_VLAN = getEntireVlans();
HIGUCHI Yutab7a15d72015-12-15 09:54:40 -080042
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 SHIMIZU55caa1c2016-05-18 23:35:02 -070050 .filter(x -> !EXCLUDED.contains(x))
HIGUCHI Yutab7a15d72015-12-15 09:54:40 -080051 .mapToObj(x -> VlanId.vlanId((short) x))
Yuta HIGUCHI498fa1d2017-05-17 16:08:40 -070052 .collect(ImmutableSet.toImmutableSet());
HIGUCHI Yutab7a15d72015-12-15 09:54:40 -080053 }
54
55}