4326b4fce1240207bf9a519389ce43949eb6f2c8
[onosfw.git] /
1 /*
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  */
16 package org.onosproject.openstackswitching;
17
18 import com.google.common.collect.Lists;
19 import org.onlab.packet.Ip4Address;
20 import org.onlab.packet.MacAddress;
21
22 import java.util.HashMap;
23 import java.util.List;
24
25 import static com.google.common.base.Preconditions.checkNotNull;
26
27 /**
28  * It represents the Openstack Port information.
29  */
30 public final class OpenstackPort {
31
32     public enum PortStatus {
33         UP,
34         DOWN
35     }
36
37     private PortStatus status;
38     private String name;
39     // FIX_ME
40     private String allowedAddressPairs;
41     private boolean adminStateUp;
42     private String networkId;
43     private String tenantId;
44     private String deviceOwner;
45     private MacAddress macAddress;
46     // <subnet id, ip address>
47     private HashMap<String, Ip4Address> fixedIps;
48     private String id;
49     private List<String> securityGroups;
50     private String deviceId;
51
52     private OpenstackPort(PortStatus status, String name, boolean adminStateUp,
53                           String networkId, String tenantId, String deviceOwner,
54                           MacAddress macAddress, HashMap fixedIps, String id,
55                           List<String> securityGroups, String deviceId) {
56
57         this.status = status;
58         this.name = name;
59         this.adminStateUp = adminStateUp;
60         this.networkId = checkNotNull(networkId);
61         this.tenantId = checkNotNull(tenantId);
62         this.deviceOwner = deviceOwner;
63         this.macAddress = checkNotNull(macAddress);
64         this.fixedIps = checkNotNull(fixedIps);
65         this.id = checkNotNull(id);
66         this.securityGroups = securityGroups;
67         this.deviceId = deviceId;
68     }
69
70
71
72     /**
73      * Returns OpenstackPort builder object.
74      *
75      * @return OpenstackPort builder
76      */
77     public static OpenstackPort.Builder builder() {
78         return new Builder();
79     }
80
81     /**
82      * Returns port status.
83      *
84      * @return port status
85      */
86     public PortStatus status() {
87         return status;
88     }
89
90     /**
91      * Returns port name.
92      *
93      * @return port name
94      */
95     public String name() {
96         return name;
97     }
98
99     /**
100      * Returns whether admin state up or not.
101      *
102      * @return true if admin state up, false otherwise
103      */
104     public boolean isAdminStateUp() {
105         return adminStateUp;
106     }
107
108     /**
109      * Returns network ID.
110      *
111      * @return network ID
112      */
113     public String networkId() {
114         return networkId;
115     }
116
117     /**
118      * Returns device owner.
119      *
120      * @return device owner
121      */
122     public String deviceOwner() {
123         return deviceOwner;
124     }
125
126     /**
127      * Returns mac address.
128      *
129      * @return mac address
130      */
131     public MacAddress macAddress() {
132         return macAddress;
133     }
134
135     /**
136      * Returns the fixed IP information.
137      *
138      * @return fixed IP info
139      */
140     public HashMap fixedIps() {
141         return fixedIps;
142     }
143
144     /**
145      * Returns port ID.
146      *
147      * @return port ID
148      */
149     public String id() {
150         return id;
151     }
152
153     /**
154      * Returns security group information.
155      *
156      * @return security group info
157      */
158     public List<String> securityGroups() {
159         return securityGroups;
160     }
161
162     /**
163      * Returns device ID.
164      *
165      * @return device ID
166      */
167     public String deviceId() {
168         return deviceId;
169     }
170
171     // TODO : Implement the following functions when necessary
172     //@Override
173     //public void equals(Object that) {
174     //
175     //}
176     //
177     //@Override
178     //public int hashCode() {
179     //
180     //}
181
182     /**
183      * OpenstackPort Builder class.
184      */
185     public static final class Builder {
186
187         private PortStatus status;
188         private String name;
189         // FIX_ME
190         private String allowedAddressPairs;
191         private boolean adminStateUp;
192         private String networkId;
193         private String tenantId;
194         private String deviceOwner;
195         private MacAddress macAddress;
196         // list  of hash map <subnet id, ip address>
197         private HashMap<String, Ip4Address> fixedIps;
198         private String id;
199         private List<String> securityGroups;
200         private String deviceId;
201
202         Builder() {
203             fixedIps = new HashMap<>();
204             securityGroups = Lists.newArrayList();
205         }
206
207         /**
208          * Sets port status.
209          *
210          * @param status port status
211          * @return Builder object
212          */
213         public Builder portStatus(PortStatus status) {
214             this.status = status;
215
216             return this;
217         }
218
219         /**
220          * Sets port name.
221          *
222          * @param name port name
223          * @return Builder object
224          */
225         public Builder name(String name) {
226             this.name = name;
227
228             return this;
229         }
230
231         /**
232          * Sets whether admin state up or not.
233          *
234          * @param isAdminStateUp true if admin state is up, false otherwise
235          * @return Builder object
236          */
237         public Builder adminState(boolean isAdminStateUp) {
238             this.adminStateUp = isAdminStateUp;
239
240             return this;
241         }
242
243         /**
244          * Sets network ID.
245          *
246          * @param networkId network ID
247          * @return Builder object
248          */
249         public Builder netwrokId(String networkId) {
250             this.networkId = networkId;
251
252             return this;
253         }
254
255         /**
256          * Sets tenant ID.
257          *
258          * @param tenantId tenant ID
259          * @return Builder object
260          */
261         public Builder tenantId(String tenantId) {
262             this.tenantId = tenantId;
263
264             return this;
265         }
266
267         /**
268          * Sets device owner.
269          *
270          * @param owner device owner
271          * @return Builder object
272          */
273         public Builder deviceOwner(String owner) {
274             this.deviceOwner = owner;
275
276             return this;
277         }
278
279         /**
280          * Sets MAC address of the port.
281          *
282          * @param mac MAC address
283          * @return Builder object
284          */
285         public Builder macAddress(MacAddress mac) {
286             this.macAddress = mac;
287
288             return this;
289         }
290
291         /**
292          * Sets Fixed IP address information.
293          *
294          * @param fixedIpList Fixed IP info
295          * @return Builder object
296          */
297         public Builder fixedIps(HashMap<String, Ip4Address> fixedIpList) {
298             fixedIps.putAll(fixedIpList);
299
300             return this;
301         }
302
303         /**
304          * Sets ID of the port.
305          *
306          * @param id ID of the port
307          * @return Builder object
308          */
309         public Builder id(String id) {
310             this.id = id;
311
312             return this;
313         }
314
315         /**
316          * Sets security group of the port.
317          *
318          * @param securityGroup security group of the port
319          * @return Builder object
320          */
321         public Builder securityGroup(String securityGroup) {
322             securityGroups.add(securityGroup);
323
324             return this;
325         }
326
327         /**
328          * Sets device ID of the port.
329          *
330          * @param deviceId device ID
331          * @return Builder object
332          */
333         public Builder deviceId(String deviceId) {
334             this.deviceId = deviceId;
335
336             return this;
337         }
338
339         /**
340          * Builds an OpenstackPort object.
341          *
342          * @return OpenstackPort objecet
343          */
344         public OpenstackPort build() {
345             return new OpenstackPort(status, name, adminStateUp, networkId, networkId,
346                     deviceOwner, macAddress, fixedIps, id, securityGroups, deviceId);
347         }
348     }
349 }
350