2 * Copyright (C) 2014 SDN Hub, LLC.
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
8 * Authors : Srini Seetharaman
11 package org.opendaylight.ovsdb.openstack.netvirt.api;
13 import com.google.common.collect.Maps;
18 * Store configuration for each load balancer instance created.
21 public class LoadBalancerConfiguration {
22 public static final String PROTOCOL_HTTP = "HTTP";
23 public static final String PROTOCOL_HTTPS = "HTTPS";
24 public static final Integer PROTOCOL_HTTP_PORT = 80;
25 public static final Integer PROTOCOL_HTTPS_PORT = 443;
27 public class LoadBalancerPoolMember {
34 public LoadBalancerPoolMember(String ipAddr, String macAddr, String protocol, Integer port) {
36 this.macAddr = macAddr;
37 this.protocol = protocol;
41 public LoadBalancerPoolMember(String ipAddr, String macAddr, String protocol, Integer port, int index) {
43 this.macAddr = macAddr;
44 this.protocol = protocol;
48 public String getIP() {
51 public String getMAC() {
54 public String getProtocol() {
57 public Integer getPort() {
60 public int getIndex() {
63 public void setIndex(int index) {
66 public boolean equals(LoadBalancerPoolMember other) {
67 if (other.ipAddr != ipAddr)
69 else if (other.macAddr != macAddr)
71 else if (other.protocol != protocol)
73 else if (other.port != port)
80 public String toString() {
81 return "LoadBalancerPoolMember [ip=" + ipAddr + ", mac=" + macAddr +
82 ", protocol=" + protocol + ", port=" + port + ", index=" + index + "]";
86 public int hashCode() {
88 int result = super.hashCode();
89 result = prime * result + ((ipAddr == null) ? 0 : ipAddr.hashCode());
90 result = prime * result + ((macAddr == null) ? 0 : macAddr.hashCode());
91 result = prime * result + ((protocol == null) ? 0 : protocol.hashCode());
92 result = prime * result + ((port == null) ? 0 : port.hashCode());
93 result = prime * result + index;
100 private Map <String, LoadBalancerPoolMember> members;
102 public LoadBalancerConfiguration() {
103 this.members = Maps.newHashMap();
106 public LoadBalancerConfiguration(String name, String vip) {
107 this.members = Maps.newHashMap();
112 public Map<String, LoadBalancerPoolMember> getMembers() {
116 public Map<String, LoadBalancerPoolMember> addMember(String uuid, LoadBalancerPoolMember member) {
117 //If index is not set for this object, update it before inserting
118 if (member.getIndex() == -1)
119 member.setIndex(members.size());
120 this.members.put(uuid, member);
123 public Map<String, LoadBalancerPoolMember> addMember(String uuid, String ipAddr, String macAddr, String protocol, Integer port) {
124 this.members.put(uuid,
125 new LoadBalancerPoolMember(ipAddr, macAddr, protocol, port, members.size()));
128 public Map<String, LoadBalancerPoolMember> removeMember(String uuid) {
129 this.members.remove(uuid);
133 public boolean isValid() {
134 if (members.size() == 0)
138 public void setVip(String vip) {
142 public String getVip() {
146 public void setName(String name) {
150 public String getName() {