blob: d23f5f3d08b9119201ec092ce63eca6dc0524f0f [file] [log] [blame]
Daniel Park5df65182016-01-09 00:12:03 +09001/*
Daniel Park3a06c522016-01-28 20:51:12 +09002 * Copyright 2015 Open Networking Laboratory
Daniel Park5df65182016-01-09 00:12:03 +09003 *
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 */
sangho0c2a3da2016-02-16 13:39:07 +090016package org.onosproject.openstacknetworking;
Daniel Park5df65182016-01-09 00:12:03 +090017
18import org.onlab.packet.Ip4Address;
sangho3623cb62016-01-15 22:06:38 +090019import org.onlab.packet.MacAddress;
Daniel Park5df65182016-01-09 00:12:03 +090020import org.onosproject.net.DeviceId;
sangho90088532016-02-25 18:06:12 +090021
22import java.util.Collection;
23import java.util.Collections;
24
Daniel Park5df65182016-01-09 00:12:03 +090025import static com.google.common.base.Preconditions.checkNotNull;
26
27/**
28 * Contains OpenstackPort Information.
29 */
Daniel Park81a61a12016-02-26 08:24:44 +090030public final class OpenstackPortInfo {
Daniel Park5df65182016-01-09 00:12:03 +090031 private final Ip4Address hostIp;
sangho3623cb62016-01-15 22:06:38 +090032 private final MacAddress hostMac;
Daniel Park3a06c522016-01-28 20:51:12 +090033 private final DeviceId deviceId;
Daniel Park5df65182016-01-09 00:12:03 +090034 private final long vni;
Daniel Park3a06c522016-01-28 20:51:12 +090035 private final Ip4Address gatewayIP;
Daniel Park81a61a12016-02-26 08:24:44 +090036 private final String networkId;
sangho90088532016-02-25 18:06:12 +090037 private final Collection<String> securityGroups;
Daniel Park5df65182016-01-09 00:12:03 +090038
sangho90088532016-02-25 18:06:12 +090039 /**
40 * Returns OpenstackPortInfo reference.
41 *
42 * @param hostIp host IP address
43 * @param hostMac host MAC address
44 * @param deviceId device ID
45 * @param vni tunnel ID
46 * @param gatewayIP gateway IP address
47 * @param securityGroups security group list
48 */
49 public OpenstackPortInfo(Ip4Address hostIp, MacAddress hostMac, DeviceId deviceId, long vni,
Daniel Park81a61a12016-02-26 08:24:44 +090050 Ip4Address gatewayIP, String networkId, Collection<String> securityGroups) {
Daniel Park5df65182016-01-09 00:12:03 +090051 this.hostIp = hostIp;
sangho3623cb62016-01-15 22:06:38 +090052 this.hostMac = hostMac;
Daniel Park5df65182016-01-09 00:12:03 +090053 this.deviceId = deviceId;
54 this.vni = vni;
Daniel Park3a06c522016-01-28 20:51:12 +090055 this.gatewayIP = gatewayIP;
Daniel Park81a61a12016-02-26 08:24:44 +090056 this.networkId = networkId;
sangho90088532016-02-25 18:06:12 +090057 this.securityGroups = securityGroups;
Daniel Park5df65182016-01-09 00:12:03 +090058 }
59
sangho90088532016-02-25 18:06:12 +090060 /**
61 * Returns IP address of the port.
62 *
63 * @return IP address
64 */
Daniel Park5df65182016-01-09 00:12:03 +090065 public Ip4Address ip() {
66 return hostIp;
67 }
68
sangho90088532016-02-25 18:06:12 +090069 /**
70 * Returns MAC address of the port.
71 *
72 * @return MAC address
73 */
sangho3623cb62016-01-15 22:06:38 +090074 public MacAddress mac() {
75 return hostMac;
76 }
77
sangho90088532016-02-25 18:06:12 +090078 /**
79 * Returns device ID.
80 *
81 * @return device ID
82 */
Daniel Park5df65182016-01-09 00:12:03 +090083 public DeviceId deviceId() {
84 return deviceId;
85 }
86
sangho90088532016-02-25 18:06:12 +090087 /**
88 * Returns tunnel ID.
89 *
90 * @return tunnel ID
91 */
Daniel Park5df65182016-01-09 00:12:03 +090092 public long vni() {
93 return vni;
94 }
95
sangho90088532016-02-25 18:06:12 +090096 /**
97 * Returns gateway IP address.
98 *
99 * @return gateway IP address
100 */
Daniel Park3a06c522016-01-28 20:51:12 +0900101 public Ip4Address gatewayIP() {
102 return gatewayIP;
103 }
104
sangho90088532016-02-25 18:06:12 +0900105 /**
Daniel Park81a61a12016-02-26 08:24:44 +0900106 * Returns network ID.
107 *
108 * @return network ID
109 */
110 public String networkId() {
111 return networkId;
112 }
113
114 /**
sangho90088532016-02-25 18:06:12 +0900115 * Returns Security Group ID list.
116 *
117 * @return list of Security Group ID
118 */
119 public Collection<String> securityGroups() {
120 return Collections.unmodifiableCollection(securityGroups);
121 }
122
123 /**
124 * Returns the builder of the OpenstackPortInfo.
125 *
126 * @return OpenstackPortInfo builder reference
127 */
Daniel Park5df65182016-01-09 00:12:03 +0900128 public static OpenstackPortInfo.Builder builder() {
129 return new Builder();
130 }
131
sangho90088532016-02-25 18:06:12 +0900132 /**
133 * Represents the OpenstackPortInfo Builder.
134 *
135 */
Daniel Park5df65182016-01-09 00:12:03 +0900136 public static final class Builder {
137 private Ip4Address hostIp;
sangho3623cb62016-01-15 22:06:38 +0900138 private MacAddress hostMac;
Daniel Park5df65182016-01-09 00:12:03 +0900139 private DeviceId deviceId;
140 private long vni;
Daniel Park3a06c522016-01-28 20:51:12 +0900141 private Ip4Address gatewayIP;
sangho90088532016-02-25 18:06:12 +0900142 private Collection<String> securityGroups;
Daniel Park81a61a12016-02-26 08:24:44 +0900143 private String networkId;
Daniel Park3a06c522016-01-28 20:51:12 +0900144
sangho90088532016-02-25 18:06:12 +0900145 /**
146 * Sets the IP address of the port.
147 *
Daniel Park81a61a12016-02-26 08:24:44 +0900148 * @param gatewayIP gateway IP
sangho90088532016-02-25 18:06:12 +0900149 * @return Builder reference
150 */
Daniel Park3a06c522016-01-28 20:51:12 +0900151 public Builder setGatewayIP(Ip4Address gatewayIP) {
152 this.gatewayIP = checkNotNull(gatewayIP, "gatewayIP cannot be null");
153 return this;
154 }
Daniel Park5df65182016-01-09 00:12:03 +0900155
sangho90088532016-02-25 18:06:12 +0900156 /**
Daniel Park81a61a12016-02-26 08:24:44 +0900157 * Sets the network ID.
158 *
159 * @param networkId network id
160 * @return Builder reference
161 */
162 public Builder setNetworkId(String networkId) {
163 this.networkId = checkNotNull(networkId, "networkId cannot be null");
164 return this;
165 }
166
167 /**
sangho90088532016-02-25 18:06:12 +0900168 * Sets the host IP address of the port.
169 *
170 * @param hostIp host IP address
171 * @return Builder reference
172 */
Daniel Park5df65182016-01-09 00:12:03 +0900173 public Builder setHostIp(Ip4Address hostIp) {
174 this.hostIp = checkNotNull(hostIp, "hostIp cannot be null");
175 return this;
176 }
177
sangho90088532016-02-25 18:06:12 +0900178 /**
179 * Sets the host MAC address of the port.
180 *
181 * @param hostMac host MAC address
182 * @return Builder reference
183 */
sangho3623cb62016-01-15 22:06:38 +0900184 public Builder setHostMac(MacAddress hostMac) {
185 this.hostMac = checkNotNull(hostMac, "hostMac cannot be bull");
186 return this;
187 }
188
sangho90088532016-02-25 18:06:12 +0900189 /**
190 * Sets the device ID.
191 *
192 * @param deviceId device ID
193 * @return Builder reference
194 */
Daniel Park5df65182016-01-09 00:12:03 +0900195 public Builder setDeviceId(DeviceId deviceId) {
196 this.deviceId = checkNotNull(deviceId, "deviceId cannot be null");
197 return this;
198 }
199
sangho90088532016-02-25 18:06:12 +0900200 /**
201 * Sets the tunnel ID.
202 *
203 * @param vni tunnel ID
204 * @return Builder reference
205 */
Jonathan Hart51539b82015-10-29 09:53:04 -0700206 public Builder setVni(long vni) {
Daniel Park5df65182016-01-09 00:12:03 +0900207 this.vni = checkNotNull(vni, "vni cannot be null");
208 return this;
209 }
sangho90088532016-02-25 18:06:12 +0900210
211 /**
212 * Sets the security group ID list.
213 *
214 * @param securityGroups security group ID list
215 * @return Builder reference
216 */
217 public Builder setSecurityGroups(Collection<String> securityGroups) {
218 this.securityGroups = securityGroups;
219 return this;
220 }
221
222 /**
223 * Builds the OpenstackPortInfo reference.
224 *
225 * @return OpenstackPortInfo reference
226 */
Daniel Park5df65182016-01-09 00:12:03 +0900227 public OpenstackPortInfo build() {
Daniel Park81a61a12016-02-26 08:24:44 +0900228 return new OpenstackPortInfo(hostIp, hostMac, deviceId, vni, gatewayIP, networkId, securityGroups);
Daniel Park5df65182016-01-09 00:12:03 +0900229 }
230 }
Daniel Park5df65182016-01-09 00:12:03 +0900231}