Daniel Park | be6b673 | 2016-11-11 15:52:19 +0900 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame^] | 2 | * Copyright 2016-present Open Networking Foundation |
Daniel Park | be6b673 | 2016-11-11 15:52:19 +0900 | [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.ofagent.impl; |
| 17 | |
| 18 | import com.google.common.collect.ImmutableSet; |
| 19 | import com.google.common.collect.Sets; |
| 20 | import org.onosproject.ofagent.api.OFSwitchCapabilities; |
| 21 | import org.projectfloodlight.openflow.protocol.OFCapabilities; |
| 22 | |
| 23 | import java.util.Set; |
| 24 | |
| 25 | /** |
| 26 | * Implementation of openflow switch capabilities. |
| 27 | */ |
| 28 | public final class DefaultOFSwitchCapabilities implements OFSwitchCapabilities { |
| 29 | |
| 30 | private final Set<OFCapabilities> ofCapabilities; |
| 31 | |
| 32 | private DefaultOFSwitchCapabilities(Set<OFCapabilities> ofSwitchCapabilities) { |
| 33 | this.ofCapabilities = ImmutableSet.copyOf(ofSwitchCapabilities); |
| 34 | } |
| 35 | |
| 36 | @Override |
| 37 | public Set<OFCapabilities> ofSwitchCapabilities() { |
| 38 | return ofCapabilities; |
| 39 | } |
| 40 | |
| 41 | /** |
| 42 | * Returns DefaultOFSwitchCapabilities builder object. |
| 43 | * |
| 44 | * @return DefaultOFSwitchCapabilities builder |
| 45 | */ |
| 46 | public static Builder builder() { |
| 47 | return new Builder(); |
| 48 | } |
| 49 | |
| 50 | public static final class Builder implements OFSwitchCapabilities.Builder { |
| 51 | private Set<OFCapabilities> ofCapabilities; |
| 52 | |
| 53 | private Builder() { |
| 54 | ofCapabilities = Sets.newHashSet(); |
| 55 | } |
| 56 | |
| 57 | @Override |
| 58 | public Builder flowStats() { |
| 59 | ofCapabilities.add(OFCapabilities.FLOW_STATS); |
| 60 | return this; |
| 61 | } |
| 62 | |
| 63 | @Override |
| 64 | public Builder tableStats() { |
| 65 | ofCapabilities.add(OFCapabilities.TABLE_STATS); |
| 66 | return this; |
| 67 | } |
| 68 | |
| 69 | @Override |
| 70 | public Builder portStats() { |
| 71 | ofCapabilities.add(OFCapabilities.PORT_STATS); |
| 72 | return this; |
| 73 | } |
| 74 | |
| 75 | @Override |
| 76 | public Builder groupStats() { |
| 77 | ofCapabilities.add(OFCapabilities.GROUP_STATS); |
| 78 | return this; |
| 79 | } |
| 80 | |
| 81 | @Override |
| 82 | public Builder ipReasm() { |
| 83 | ofCapabilities.add(OFCapabilities.IP_REASM); |
| 84 | return this; |
| 85 | } |
| 86 | |
| 87 | @Override |
| 88 | public Builder queueStats() { |
| 89 | ofCapabilities.add(OFCapabilities.QUEUE_STATS); |
| 90 | return this; |
| 91 | } |
| 92 | |
| 93 | @Override |
| 94 | public Builder portBlocked() { |
| 95 | ofCapabilities.add(OFCapabilities.PORT_BLOCKED); |
| 96 | return this; |
| 97 | } |
| 98 | |
| 99 | @Override |
| 100 | public OFSwitchCapabilities build() { |
| 101 | return new DefaultOFSwitchCapabilities(ofCapabilities); |
| 102 | } |
| 103 | } |
| 104 | } |