blob: 1d5f550e72e4e57aeb3e89042758ac43e8ef7bf2 [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;
Hyunsun Moon1251e192016-06-07 16:57:05 -070042 private final Optional<Boolean> disableInBand;
43
44 /* Adds more configurations */
45
46 private DefaultBridgeDescription(String name,
47 List<ControllerInfo> controllers,
48 boolean enableLocalController,
49 Optional<FailMode> failMode,
50 Optional<String> datapathId,
jaegonkim80bee532017-05-15 15:16:38 +090051 Optional<String> datapathType,
Hyunsun Moon1251e192016-06-07 16:57:05 -070052 Optional<Boolean> disableInBand) {
53 this.name = checkNotNull(name);
54 this.controllers = controllers;
55 this.enableLocalController = enableLocalController;
56 this.failMode = failMode;
57 this.datapathId = datapathId;
jaegonkim80bee532017-05-15 15:16:38 +090058 this.datapathType = datapathType;
Hyunsun Moon1251e192016-06-07 16:57:05 -070059 this.disableInBand = disableInBand;
samuel8d6b0a92015-07-11 13:22:57 +080060 }
61
62 @Override
Hyunsun Moon1251e192016-06-07 16:57:05 -070063 public SparseAnnotations annotations() {
64 return null;
65 }
66
67 @Override
68 public String name() {
samuel8d6b0a92015-07-11 13:22:57 +080069 return name;
70 }
71
72 @Override
Hyunsun Moon1251e192016-06-07 16:57:05 -070073 public List<ControllerInfo> controllers() {
74 return controllers;
samuel8d6b0a92015-07-11 13:22:57 +080075 }
76
77 @Override
Hyunsun Moon1251e192016-06-07 16:57:05 -070078 public boolean enableLocalController() {
79 return enableLocalController;
samuel8d6b0a92015-07-11 13:22:57 +080080 }
81
82 @Override
Hyunsun Moon1251e192016-06-07 16:57:05 -070083 public Optional<FailMode> failMode() {
84 return failMode;
samuel8d6b0a92015-07-11 13:22:57 +080085 }
86
87 @Override
Hyunsun Moon1251e192016-06-07 16:57:05 -070088 public Optional<String> datapathId() {
89 return datapathId;
90 }
91
92 @Override
jaegonkim80bee532017-05-15 15:16:38 +090093 public Optional<String> datapathType() {
94 return datapathType;
95 }
96
97 @Override
Hyunsun Moon1251e192016-06-07 16:57:05 -070098 public Optional<DeviceId> deviceId() {
99 if (datapathId.isPresent()) {
100 return Optional.of(DeviceId.deviceId("of:" + datapathId.get()));
101 } else {
102 return Optional.empty();
samuel8d6b0a92015-07-11 13:22:57 +0800103 }
samuel8d6b0a92015-07-11 13:22:57 +0800104 }
105
106 @Override
Hyunsun Moon1251e192016-06-07 16:57:05 -0700107 public Optional<Boolean> disableInBand() {
108 return disableInBand;
samuel8d6b0a92015-07-11 13:22:57 +0800109 }
110
Hyunsun Moon1251e192016-06-07 16:57:05 -0700111 /**
112 * Creates and returns a new builder instance.
113 *
114 * @return new builder
115 */
116 public static BridgeDescription.Builder builder() {
117 return new Builder();
118 }
119
120 public static final class Builder implements BridgeDescription.Builder {
121
122 private String name;
123 private List<ControllerInfo> controllers = Lists.newArrayList();
124 private boolean enableLocalController = false;
125 private Optional<FailMode> failMode = Optional.empty();
126 private Optional<String> datapathId = Optional.empty();
jaegonkim80bee532017-05-15 15:16:38 +0900127 private Optional<String> datapathType = Optional.empty();
Hyunsun Moon1251e192016-06-07 16:57:05 -0700128 private Optional<Boolean> disableInBand = Optional.empty();
129
130 private Builder() {
131 }
132
133 @Override
134 public BridgeDescription build() {
135 return new DefaultBridgeDescription(name, controllers,
136 enableLocalController,
137 failMode,
138 datapathId,
jaegonkim80bee532017-05-15 15:16:38 +0900139 datapathType,
Hyunsun Moon1251e192016-06-07 16:57:05 -0700140 disableInBand);
141 }
142
143 @Override
144 public Builder name(String name) {
145 checkArgument(!Strings.isNullOrEmpty(name));
146 this.name = name;
147 return this;
148 }
149
150 @Override
151 public Builder controllers(List<ControllerInfo> controllers) {
152 if (controllers != null) {
153 this.controllers = Lists.newArrayList(controllers);
154 }
155 return this;
156 }
157
158 @Override
159 public Builder enableLocalController() {
160 this.enableLocalController = true;
161 return this;
162 }
163
164 @Override
165 public Builder failMode(FailMode failMode) {
166 this.failMode = Optional.ofNullable(failMode);
167 return this;
168 }
169
170 @Override
171 public Builder datapathId(String datapathId) {
172 this.datapathId = Optional.ofNullable(datapathId);
173 return this;
174 }
175
176 @Override
jaegonkim80bee532017-05-15 15:16:38 +0900177 public Builder datapathType(String datapathType) {
178 this.datapathType = Optional.ofNullable(datapathType);
179 return this;
180 }
181
182 @Override
Hyunsun Moon1251e192016-06-07 16:57:05 -0700183 public Builder disableInBand() {
184 this.disableInBand = Optional.of(Boolean.TRUE);
185 return this;
186 }
187 }
samuel8d6b0a92015-07-11 13:22:57 +0800188}