blob: 292192a0efe75407cdf4de105b043521a25385d2 [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.VlanId;
22import org.onlab.util.GuavaCollectors;
23import 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;
38 private static final Set<VlanId> ENTIRE_VLAN = getEntireVlans();
39
40 @Override
41 public Set<VlanId> queryVlanIds(PortNumber port) {
42 return ENTIRE_VLAN;
43 }
44
45 private static Set<VlanId> getEntireVlans() {
46 return IntStream.range(0, MAX_VLAN_ID)
47 .mapToObj(x -> VlanId.vlanId((short) x))
48 .collect(GuavaCollectors.toImmutableSet());
49 }
50
51}