2 * Copyright (c) 2014, 2015 SDN Hub, LLC. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.netvirt.openstack.netvirt.api;
11 import com.google.common.collect.Maps;
16 * Store configuration for each load balancer instance created.
19 public class LoadBalancerConfiguration {
20 public static final String PROTOCOL_TCP = "TCP";
21 public static final String PROTOCOL_HTTP = "HTTP";
22 public static final String PROTOCOL_HTTPS = "HTTPS";
24 public class LoadBalancerPoolMember {
31 public LoadBalancerPoolMember(String ipAddr, String macAddr, String protocol, Integer port) {
33 this.macAddr = macAddr;
34 this.protocol = protocol;
38 public LoadBalancerPoolMember(String ipAddr, String macAddr, String protocol, Integer port, int index) {
40 this.macAddr = macAddr;
41 this.protocol = protocol;
45 public String getIP() {
48 public String getMAC() {
51 public String getProtocol() {
54 public Integer getPort() {
57 public int getIndex() {
60 public void setIndex(int index) {
65 * Overridden equals() where index is not checked.
68 public boolean equals(Object obj) {
75 if (getClass() != obj.getClass()) {
78 LoadBalancerPoolMember other = (LoadBalancerPoolMember) obj;
80 if (other.ipAddr != null) {
83 } else if (!ipAddr.equals(other.ipAddr)) {
86 if (macAddr == null) {
87 if (other.macAddr != null) {
90 } else if (!macAddr.equals(other.macAddr)) {
94 if (other.port != null) {
97 } else if (!port.equals(other.port)) {
100 if (protocol == null) {
101 if (other.protocol != null) {
104 } else if (!protocol.equals(other.protocol)) {
111 public String toString() {
112 return "LoadBalancerPoolMember [ip=" + ipAddr + ", mac=" + macAddr +
113 ", protocol=" + protocol + ", port=" + port + ", index=" + index + "]";
117 public int hashCode() {
118 final int prime = 31;
120 result = prime * result + ((ipAddr == null) ? 0 : ipAddr.hashCode());
121 result = prime * result + ((macAddr == null) ? 0 : macAddr.hashCode());
122 result = prime * result + ((protocol == null) ? 0 : protocol.hashCode());
123 result = prime * result + ((port == null) ? 0 : port.hashCode());
130 private String vmac; //Used when a dummy neutron port is created for the VIP
131 private String providerNetworkType;
132 private String providerSegmentationId;
133 private Map <String, LoadBalancerPoolMember> members;
135 public LoadBalancerConfiguration() {
136 this.members = Maps.newHashMap();
139 public LoadBalancerConfiguration(String name, String vip) {
140 this.members = Maps.newHashMap();
146 public LoadBalancerConfiguration(String name, String vip, String vmac) {
147 this.members = Maps.newHashMap();
153 public LoadBalancerConfiguration(LoadBalancerConfiguration lbConfig) {
154 this.members = Maps.newHashMap(lbConfig.getMembers());
155 this.name = lbConfig.getName();
156 this.vip = lbConfig.getVip();
157 this.vmac = lbConfig.getVmac();
158 this.providerNetworkType = lbConfig.getProviderNetworkType();
159 this.providerSegmentationId = lbConfig.getProviderSegmentationId();
162 public Map<String, LoadBalancerPoolMember> getMembers() {
166 public Map<String, LoadBalancerPoolMember> addMember(String uuid, LoadBalancerPoolMember member) {
167 //If index is not set for this object, update it before inserting
168 if (member.getIndex() == -1) {
169 member.setIndex(members.size());
171 this.members.put(uuid, member);
174 public Map<String, LoadBalancerPoolMember> addMember(String uuid, String ipAddr, String macAddr, String protocol, Integer port) {
175 this.members.put(uuid,
176 new LoadBalancerPoolMember(ipAddr, macAddr, protocol, port, members.size()));
179 public Map<String, LoadBalancerPoolMember> removeMember(String uuid) {
180 this.members.remove(uuid);
181 /* Update indices of all other members
184 for(Map.Entry<String, LoadBalancerPoolMember> entry : this.getMembers().entrySet()) {
185 entry.getValue().setIndex(index++);
190 public boolean isValid() {
191 if (members.size() == 0) {
193 } else if (providerNetworkType == null) {
199 public void setVip(String vip) {
203 public String getVip() {
207 public void setVmac(String vmac) {
211 public String getVmac() {
215 public void setName(String name) {
219 public String getName() {
223 public void setProviderSegmentationId(String providerSegmentationId) {
224 this.providerSegmentationId = providerSegmentationId;
227 public String getProviderSegmentationId() {
228 return this.providerSegmentationId;
230 public void setProviderNetworkType(String providerNetworkType) {
231 this.providerNetworkType = providerNetworkType;
234 public String getProviderNetworkType() {
235 return this.providerNetworkType;
239 public String toString() {
240 return "LoadBalancerConfiguration [name=" + name +
241 ", vip=" + vip + ", vmac=" + vmac +
242 ", networkType=" + providerNetworkType +
243 ", segmentationId=" + providerSegmentationId +
244 ", members=" + members + "]";