Merge "L3: Break exclusions and rewrites into inbound and outbound conterparts."
[netvirt.git] / openstack / net-virt / src / main / java / org / opendaylight / ovsdb / openstack / netvirt / api / LoadBalancerConfiguration.java
1 /*
2  * Copyright (C) 2014 SDN Hub, LLC.
3  *
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
7  *
8  * Authors : Srini Seetharaman
9  */
10
11 package org.opendaylight.ovsdb.openstack.netvirt.api;
12
13 import com.google.common.collect.Maps;
14
15 import java.util.Map;
16
17 /**
18  * Store configuration for each load balancer instance created.
19  */
20
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;
26
27     public class LoadBalancerPoolMember {
28         String ipAddr;
29         String macAddr;
30         String protocol;
31         Integer port;
32         int index;
33
34         public LoadBalancerPoolMember(String ipAddr, String macAddr, String protocol, Integer port) {
35             this.ipAddr = ipAddr;
36             this.macAddr = macAddr;
37             this.protocol = protocol;
38             this.port = port;
39             this.index = -1;
40         }
41         public LoadBalancerPoolMember(String ipAddr, String macAddr, String protocol, Integer port, int index) {
42             this.ipAddr = ipAddr;
43             this.macAddr = macAddr;
44             this.protocol = protocol;
45             this.port = port;
46             this.index = index;
47         }
48         public String getIP() {
49             return ipAddr;
50         }
51         public String getMAC() {
52             return macAddr;
53         }
54         public String getProtocol() {
55             return protocol;
56         }
57         public Integer getPort() {
58             return port;
59         }
60         public int getIndex() {
61             return index;
62         }
63         public void setIndex(int index) {
64             this.index = index;
65         }
66         public boolean equals(LoadBalancerPoolMember other) {
67             if (other.ipAddr != ipAddr)
68                 return false;
69             else if (other.macAddr != macAddr)
70                 return false;
71             else if (other.protocol != protocol)
72                 return false;
73             else if (other.port != port)
74                 return false;
75             //Ignore Index
76             return true;
77         }
78
79         @Override
80         public String toString() {
81             return "LoadBalancerPoolMember [ip=" + ipAddr + ", mac=" + macAddr +
82                     ", protocol=" + protocol + ", port=" + port + ", index=" + index + "]";
83         }
84
85         @Override
86         public int hashCode() {
87             final int prime = 31;
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;
94             return result;
95         }
96     }
97
98     private String name;
99     private String vip;
100     private Map <String, LoadBalancerPoolMember> members;
101
102     public LoadBalancerConfiguration() {
103         this.members = Maps.newHashMap();
104     }
105
106     public LoadBalancerConfiguration(String name, String vip) {
107         this.members = Maps.newHashMap();
108         this.name = name;
109         this.vip = vip;
110     }
111
112     public Map<String, LoadBalancerPoolMember> getMembers() {
113         return this.members;
114     }
115
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);
121         return this.members;
122     }
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()));
126         return this.members;
127     }
128     public Map<String, LoadBalancerPoolMember> removeMember(String uuid) {
129         this.members.remove(uuid);
130         return this.members;
131     }
132
133     public boolean isValid() {
134         if (members.size() == 0)
135             return false;
136         return true;
137     }
138     public void setVip(String vip) {
139         this.vip = vip;
140     }
141
142     public String getVip() {
143         return this.vip;
144     }
145
146     public void setName(String name) {
147         this.name = name;
148     }
149
150     public String getName() {
151         return this.name;
152     }
153 }