blob: 609c71b18e22fb703c90528e080a5d241ea0f133 [file] [log] [blame]
samuel8d6b0a92015-07-11 13:22:57 +08001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2015-present Open Networking Foundation
samuel8d6b0a92015-07-11 13:22:57 +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.net.behaviour;
17
Hyunsun Moon1251e192016-06-07 16:57:05 -070018import com.google.common.base.Strings;
19import com.google.common.collect.Lists;
samuel8d6b0a92015-07-11 13:22:57 +080020import org.onosproject.net.DeviceId;
21import org.onosproject.net.SparseAnnotations;
22
Hyunsun Moon1251e192016-06-07 16:57:05 -070023import java.util.List;
24import java.util.Optional;
25
26import static com.google.common.base.Preconditions.checkArgument;
27import static com.google.common.base.Preconditions.checkNotNull;
samuel8d6b0a92015-07-11 13:22:57 +080028
29/**
30 * The default implementation of bridge.
31 */
Hyunsun Moon1251e192016-06-07 16:57:05 -070032public final class DefaultBridgeDescription implements BridgeDescription {
samuel8d6b0a92015-07-11 13:22:57 +080033
Hyunsun Moon1251e192016-06-07 16:57:05 -070034 private final String name;
samuel8d6b0a92015-07-11 13:22:57 +080035
Hyunsun Moon1251e192016-06-07 16:57:05 -070036 /* Optional OpenFlow configurations */
37 private final List<ControllerInfo> controllers;
38 private final boolean enableLocalController;
39 private final Optional<FailMode> failMode;
40 private final Optional<String> datapathId;
jaegonkim80bee532017-05-15 15:16:38 +090041 private final Optional<String> datapathType;
rohitsharana127ba82018-01-16 02:17:30 +053042 private final Optional<List<ControlProtocolVersion>> controlProtocols;
Hyunsun Moon1251e192016-06-07 16:57:05 -070043 private final Optional<Boolean> disableInBand;
Jian Li0aed0e62020-12-12 03:54:54 +090044 private final Optional<Boolean> mcastSnoopingEnable;
Hyunsun Moon1251e192016-06-07 16:57:05 -070045
46 /* Adds more configurations */
47
48 private DefaultBridgeDescription(String name,
49 List<ControllerInfo> controllers,
50 boolean enableLocalController,
51 Optional<FailMode> failMode,
52 Optional<String> datapathId,
jaegonkim80bee532017-05-15 15:16:38 +090053 Optional<String> datapathType,
rohitsharana127ba82018-01-16 02:17:30 +053054 Optional<Boolean> disableInBand,
Jian Li0aed0e62020-12-12 03:54:54 +090055 Optional<Boolean> mcastSnoopingEnable,
rohitsharana127ba82018-01-16 02:17:30 +053056 Optional<List<ControlProtocolVersion>> controlProtocols) {
Hyunsun Moon1251e192016-06-07 16:57:05 -070057 this.name = checkNotNull(name);
58 this.controllers = controllers;
59 this.enableLocalController = enableLocalController;
60 this.failMode = failMode;
61 this.datapathId = datapathId;
jaegonkim80bee532017-05-15 15:16:38 +090062 this.datapathType = datapathType;
Hyunsun Moon1251e192016-06-07 16:57:05 -070063 this.disableInBand = disableInBand;
Jian Li0aed0e62020-12-12 03:54:54 +090064 this.mcastSnoopingEnable = mcastSnoopingEnable;
rohitsharana127ba82018-01-16 02:17:30 +053065 this.controlProtocols = controlProtocols;
samuel8d6b0a92015-07-11 13:22:57 +080066 }
67
68 @Override
Hyunsun Moon1251e192016-06-07 16:57:05 -070069 public SparseAnnotations annotations() {
70 return null;
71 }
72
73 @Override
74 public String name() {
samuel8d6b0a92015-07-11 13:22:57 +080075 return name;
76 }
77
78 @Override
Hyunsun Moon1251e192016-06-07 16:57:05 -070079 public List<ControllerInfo> controllers() {
80 return controllers;
samuel8d6b0a92015-07-11 13:22:57 +080081 }
82
83 @Override
Hyunsun Moon1251e192016-06-07 16:57:05 -070084 public boolean enableLocalController() {
85 return enableLocalController;
samuel8d6b0a92015-07-11 13:22:57 +080086 }
87
88 @Override
Hyunsun Moon1251e192016-06-07 16:57:05 -070089 public Optional<FailMode> failMode() {
90 return failMode;
samuel8d6b0a92015-07-11 13:22:57 +080091 }
92
93 @Override
Hyunsun Moon1251e192016-06-07 16:57:05 -070094 public Optional<String> datapathId() {
95 return datapathId;
96 }
97
98 @Override
jaegonkim80bee532017-05-15 15:16:38 +090099 public Optional<String> datapathType() {
100 return datapathType;
101 }
102
103 @Override
rohitsharana127ba82018-01-16 02:17:30 +0530104 public Optional<List<ControlProtocolVersion>> controlProtocols() {
105 return controlProtocols;
106 }
107
108 @Override
Hyunsun Moon1251e192016-06-07 16:57:05 -0700109 public Optional<DeviceId> deviceId() {
110 if (datapathId.isPresent()) {
111 return Optional.of(DeviceId.deviceId("of:" + datapathId.get()));
112 } else {
113 return Optional.empty();
samuel8d6b0a92015-07-11 13:22:57 +0800114 }
samuel8d6b0a92015-07-11 13:22:57 +0800115 }
116
117 @Override
Hyunsun Moon1251e192016-06-07 16:57:05 -0700118 public Optional<Boolean> disableInBand() {
119 return disableInBand;
samuel8d6b0a92015-07-11 13:22:57 +0800120 }
121
Jian Li0aed0e62020-12-12 03:54:54 +0900122 @Override
123 public Optional<Boolean> mcastSnoopingEnable() {
124 return mcastSnoopingEnable;
125 }
126
Hyunsun Moon1251e192016-06-07 16:57:05 -0700127 /**
128 * Creates and returns a new builder instance.
129 *
130 * @return new builder
131 */
132 public static BridgeDescription.Builder builder() {
133 return new Builder();
134 }
135
136 public static final class Builder implements BridgeDescription.Builder {
137
138 private String name;
139 private List<ControllerInfo> controllers = Lists.newArrayList();
140 private boolean enableLocalController = false;
141 private Optional<FailMode> failMode = Optional.empty();
142 private Optional<String> datapathId = Optional.empty();
jaegonkim80bee532017-05-15 15:16:38 +0900143 private Optional<String> datapathType = Optional.empty();
rohitsharana127ba82018-01-16 02:17:30 +0530144 private Optional<List<ControlProtocolVersion>> controlProtocols = Optional.empty();
Hyunsun Moon1251e192016-06-07 16:57:05 -0700145 private Optional<Boolean> disableInBand = Optional.empty();
Jian Li0aed0e62020-12-12 03:54:54 +0900146 private Optional<Boolean> mcastSnoopingEnable = Optional.empty();
Hyunsun Moon1251e192016-06-07 16:57:05 -0700147
148 private Builder() {
149 }
150
151 @Override
152 public BridgeDescription build() {
153 return new DefaultBridgeDescription(name, controllers,
154 enableLocalController,
155 failMode,
156 datapathId,
jaegonkim80bee532017-05-15 15:16:38 +0900157 datapathType,
rohitsharana127ba82018-01-16 02:17:30 +0530158 disableInBand,
Jian Li0aed0e62020-12-12 03:54:54 +0900159 mcastSnoopingEnable,
rohitsharana127ba82018-01-16 02:17:30 +0530160 controlProtocols);
Hyunsun Moon1251e192016-06-07 16:57:05 -0700161 }
162
163 @Override
164 public Builder name(String name) {
165 checkArgument(!Strings.isNullOrEmpty(name));
166 this.name = name;
167 return this;
168 }
169
170 @Override
171 public Builder controllers(List<ControllerInfo> controllers) {
172 if (controllers != null) {
173 this.controllers = Lists.newArrayList(controllers);
174 }
175 return this;
176 }
177
178 @Override
179 public Builder enableLocalController() {
180 this.enableLocalController = true;
181 return this;
182 }
183
184 @Override
185 public Builder failMode(FailMode failMode) {
186 this.failMode = Optional.ofNullable(failMode);
187 return this;
188 }
189
190 @Override
191 public Builder datapathId(String datapathId) {
192 this.datapathId = Optional.ofNullable(datapathId);
193 return this;
194 }
195
196 @Override
jaegonkim80bee532017-05-15 15:16:38 +0900197 public Builder datapathType(String datapathType) {
198 this.datapathType = Optional.ofNullable(datapathType);
199 return this;
200 }
201
202 @Override
rohitsharana127ba82018-01-16 02:17:30 +0530203 public Builder controlProtocols(List<ControlProtocolVersion> controlProtocols) {
204 this.controlProtocols = Optional.ofNullable(controlProtocols);
205 return this;
206 }
207
208 @Override
Hyunsun Moon1251e192016-06-07 16:57:05 -0700209 public Builder disableInBand() {
210 this.disableInBand = Optional.of(Boolean.TRUE);
211 return this;
212 }
Jian Li0aed0e62020-12-12 03:54:54 +0900213
214 @Override
215 public BridgeDescription.Builder mcastSnoopingEnable() {
216 this.mcastSnoopingEnable = Optional.of(Boolean.TRUE);
217 return this;
218 }
Hyunsun Moon1251e192016-06-07 16:57:05 -0700219 }
samuel8d6b0a92015-07-11 13:22:57 +0800220}