sangho | 5db8e05 | 2016-01-29 16:08:23 +0900 | [diff] [blame] | 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 | */ |
sangho | 0c2a3da | 2016-02-16 13:39:07 +0900 | [diff] [blame^] | 16 | package org.onosproject.openstacknetworking; |
| 17 | |
| 18 | import java.util.Objects; |
| 19 | |
| 20 | import static com.google.common.base.Preconditions.checkNotNull; |
sangho | 5db8e05 | 2016-01-29 16:08:23 +0900 | [diff] [blame] | 21 | |
| 22 | /** |
| 23 | * Represents Openstack Security Group Rules. |
| 24 | */ |
| 25 | public final class OpenstackSecurityGroupRule { |
| 26 | |
sangho | 0c2a3da | 2016-02-16 13:39:07 +0900 | [diff] [blame^] | 27 | private final String direction; |
| 28 | private final String ethertype; |
| 29 | private final String id; |
| 30 | private final String portRangeMax; |
| 31 | private final String portRangeMin; |
| 32 | private final String protocol; |
| 33 | private final String remoteGroupId; |
| 34 | private final String remoteIpPrefix; |
| 35 | private final String secuityGroupId; |
| 36 | private final String tenantId; |
sangho | 5db8e05 | 2016-01-29 16:08:23 +0900 | [diff] [blame] | 37 | |
| 38 | private OpenstackSecurityGroupRule(String direction, |
| 39 | String ethertype, |
| 40 | String id, |
| 41 | String portRangeMax, |
| 42 | String portRangeMin, |
| 43 | String protocol, |
| 44 | String remoteGroupId, |
| 45 | String remoteIpPrefix, |
| 46 | String securityGroupId, |
| 47 | String tenantId) { |
| 48 | this.direction = direction; |
| 49 | this.ethertype = ethertype; |
sangho | 0c2a3da | 2016-02-16 13:39:07 +0900 | [diff] [blame^] | 50 | this.id = checkNotNull(id); |
sangho | 5db8e05 | 2016-01-29 16:08:23 +0900 | [diff] [blame] | 51 | this.portRangeMax = portRangeMax; |
| 52 | this.portRangeMin = portRangeMin; |
| 53 | this.protocol = protocol; |
| 54 | this.remoteGroupId = remoteGroupId; |
| 55 | this.remoteIpPrefix = remoteIpPrefix; |
| 56 | this.secuityGroupId = securityGroupId; |
| 57 | this.tenantId = tenantId; |
| 58 | } |
| 59 | |
sangho | 5db8e05 | 2016-01-29 16:08:23 +0900 | [diff] [blame] | 60 | @Override |
| 61 | public String toString() { |
| 62 | return new StringBuilder(" [") |
| 63 | .append(direction + ",") |
| 64 | .append(ethertype + ",") |
| 65 | .append(id + ",") |
| 66 | .append(portRangeMax + ",") |
| 67 | .append(portRangeMin + ",") |
| 68 | .append(protocol + ",'") |
| 69 | .append(remoteGroupId + ",") |
| 70 | .append(remoteIpPrefix + ",") |
| 71 | .append(secuityGroupId + ",") |
| 72 | .append(tenantId + "] ") |
| 73 | .toString(); |
| 74 | } |
| 75 | |
sangho | 0c2a3da | 2016-02-16 13:39:07 +0900 | [diff] [blame^] | 76 | @Override |
| 77 | public boolean equals(Object o) { |
| 78 | if (this == o) { |
| 79 | return true; |
| 80 | } |
| 81 | |
| 82 | if (this instanceof OpenstackSecurityGroupRule) { |
| 83 | OpenstackSecurityGroupRule that = (OpenstackSecurityGroupRule) o; |
| 84 | return this.direction.equals(that.direction) && |
| 85 | this.ethertype.equals(that.direction) && |
| 86 | this.id.equals(that.id) && |
| 87 | this.portRangeMax.equals(that.portRangeMax) && |
| 88 | this.portRangeMin.equals(that.portRangeMin) && |
| 89 | this.protocol.equals(that.protocol) && |
| 90 | this.remoteGroupId.equals(that.remoteGroupId) && |
| 91 | this.secuityGroupId.equals(that.secuityGroupId) && |
| 92 | this.remoteIpPrefix.equals(that.remoteIpPrefix) && |
| 93 | this.tenantId.equals(that.tenantId); |
| 94 | } |
| 95 | |
| 96 | return false; |
| 97 | } |
| 98 | |
| 99 | @Override |
| 100 | public int hashCode() { |
| 101 | return Objects.hash(direction, ethertype, id, portRangeMax, portRangeMin, protocol, |
| 102 | remoteGroupId, remoteIpPrefix, secuityGroupId, tenantId); |
| 103 | } |
| 104 | |
sangho | 5db8e05 | 2016-01-29 16:08:23 +0900 | [diff] [blame] | 105 | /** |
| 106 | * Represents a security group rule builder object. |
| 107 | */ |
| 108 | public static final class Builder { |
| 109 | |
| 110 | private String direction; |
| 111 | private String etherType; |
| 112 | private String id; |
| 113 | private String portRangeMax; |
| 114 | private String portRangeMin; |
| 115 | private String protocol; |
| 116 | private String remoteGroupId; |
| 117 | private String remoteIpPrefix; |
| 118 | private String secuityGroupId; |
| 119 | private String tenantId; |
| 120 | |
| 121 | |
| 122 | /** |
| 123 | * Sets the direction of the security group rule. |
| 124 | * |
| 125 | * @param direction direction (ingress or egress) |
| 126 | * @return builder object |
| 127 | */ |
| 128 | public Builder direction(String direction) { |
| 129 | this.direction = direction; |
| 130 | return this; |
| 131 | } |
| 132 | |
| 133 | /** |
| 134 | * Sets the Ethernet Type. |
| 135 | * |
| 136 | * @param etherType Ethernet Type |
| 137 | * @return builder object |
| 138 | */ |
| 139 | public Builder etherType(String etherType) { |
| 140 | this.etherType = etherType; |
| 141 | return this; |
| 142 | } |
| 143 | |
| 144 | /** |
| 145 | * Sets the Security Group Rule ID. |
| 146 | * |
| 147 | * @param id security group rule ID |
| 148 | * @return builder object |
| 149 | */ |
| 150 | public Builder id(String id) { |
| 151 | this.id = id; |
| 152 | return this; |
| 153 | } |
| 154 | |
| 155 | /** |
| 156 | * Sets the port range max value. |
| 157 | * |
| 158 | * @param portRangeMax port range max value |
| 159 | * @return builder object |
| 160 | */ |
| 161 | public Builder portRangeMax(String portRangeMax) { |
| 162 | this.portRangeMax = portRangeMax; |
| 163 | return this; |
| 164 | } |
| 165 | |
| 166 | /** |
| 167 | * Sets the port range min value. |
| 168 | * |
| 169 | * @param portRangeMin port range min value |
| 170 | * @return builder object |
| 171 | */ |
| 172 | public Builder portRangeMin(String portRangeMin) { |
| 173 | this.portRangeMin = portRangeMin; |
| 174 | return this; |
| 175 | } |
| 176 | |
| 177 | /** |
| 178 | * Sets the protocol. |
| 179 | * |
| 180 | * @param protocol protocol |
| 181 | * @return builder object |
| 182 | */ |
| 183 | public Builder protocol(String protocol) { |
| 184 | this.protocol = protocol; |
| 185 | return this; |
| 186 | } |
| 187 | |
| 188 | /** |
| 189 | * Sets the remote security group ID. |
| 190 | * |
| 191 | * @param remoteGroupId remote security group ID |
| 192 | * @return builder |
| 193 | */ |
| 194 | public Builder remoteGroupId(String remoteGroupId) { |
| 195 | this.remoteGroupId = remoteGroupId; |
| 196 | return this; |
| 197 | } |
| 198 | |
| 199 | /** |
| 200 | * Sets the remote IP address as prefix. |
| 201 | * |
| 202 | * @param remoteIpPrefix remote IP address |
| 203 | * @return builder object |
| 204 | */ |
| 205 | public Builder remoteIpPrefix(String remoteIpPrefix) { |
| 206 | this.remoteIpPrefix = remoteIpPrefix; |
| 207 | return this; |
| 208 | } |
| 209 | |
| 210 | /** |
| 211 | * Sets the Security Group ID. |
| 212 | * |
| 213 | * @param securityGroupId security group ID |
| 214 | * @return builder object |
| 215 | */ |
| 216 | public Builder securityGroupId(String securityGroupId) { |
| 217 | this.secuityGroupId = securityGroupId; |
| 218 | return this; |
| 219 | } |
| 220 | |
| 221 | /** |
| 222 | * Sets the tenant ID. |
| 223 | * |
| 224 | * @param tenantId tenant ID |
| 225 | * @return builder object |
| 226 | */ |
| 227 | public Builder tenantId(String tenantId) { |
| 228 | this.tenantId = tenantId; |
| 229 | return this; |
| 230 | } |
| 231 | |
| 232 | /** |
| 233 | * Creates a OpenstackSecurityGroupRule instance. |
| 234 | * |
| 235 | * @return OpenstackSecurityGroupRule object |
| 236 | */ |
| 237 | public OpenstackSecurityGroupRule build() { |
| 238 | return new OpenstackSecurityGroupRule(direction, etherType, id, portRangeMax, |
| 239 | portRangeMin, protocol, remoteGroupId, remoteIpPrefix, secuityGroupId, tenantId); |
| 240 | } |
| 241 | } |
| 242 | } |