Skip to content

Commit 48308ec

Browse files
committed
Redoing NatRule usage and some fixes based on issues found while writing
unittests
1 parent 700050a commit 48308ec

6 files changed

Lines changed: 277 additions & 81 deletions

File tree

‎plugins/network-elements/nicira-nvp/src/com/cloud/network/nicira/DestinationNatRule.java‎

Lines changed: 0 additions & 24 deletions
This file was deleted.

‎plugins/network-elements/nicira-nvp/src/com/cloud/network/nicira/Match.java‎

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,126 @@ public Boolean isDestinationIpAddressesNot() {
128128
public void setDestinationIpAddressesNot(Boolean destination_ip_addresses_not) {
129129
this.destination_ip_addresses_not = destination_ip_addresses_not;
130130
}
131+
132+
@Override
133+
public int hashCode() {
134+
final int prime = 31;
135+
int result = 1;
136+
result = prime
137+
* result
138+
+ ((destination_ip_addresses == null) ? 0
139+
: destination_ip_addresses.hashCode());
140+
result = prime
141+
* result
142+
+ ((destination_ip_addresses_not == null) ? 0
143+
: destination_ip_addresses_not.hashCode());
144+
result = prime
145+
* result
146+
+ ((destination_port_max == null) ? 0 : destination_port_max
147+
.hashCode());
148+
result = prime
149+
* result
150+
+ ((destination_port_min == null) ? 0 : destination_port_min
151+
.hashCode());
152+
result = prime
153+
* result
154+
+ ((destination_port_not == null) ? 0 : destination_port_not
155+
.hashCode());
156+
result = prime * result
157+
+ ((ethertype == null) ? 0 : ethertype.hashCode());
158+
result = prime * result
159+
+ ((protocol == null) ? 0 : protocol.hashCode());
160+
result = prime
161+
* result
162+
+ ((source_ip_addresses == null) ? 0 : source_ip_addresses
163+
.hashCode());
164+
result = prime
165+
* result
166+
+ ((source_ip_addresses_not == null) ? 0
167+
: source_ip_addresses_not.hashCode());
168+
result = prime * result
169+
+ ((source_port_max == null) ? 0 : source_port_max.hashCode());
170+
result = prime * result
171+
+ ((source_port_min == null) ? 0 : source_port_min.hashCode());
172+
result = prime * result
173+
+ ((source_port_not == null) ? 0 : source_port_not.hashCode());
174+
return result;
175+
}
176+
177+
@Override
178+
public boolean equals(Object obj) {
179+
if (this == obj)
180+
return true;
181+
if (obj == null)
182+
return false;
183+
if (getClass() != obj.getClass())
184+
return false;
185+
Match other = (Match) obj;
186+
if (destination_ip_addresses == null) {
187+
if (other.destination_ip_addresses != null)
188+
return false;
189+
} else if (!destination_ip_addresses
190+
.equals(other.destination_ip_addresses))
191+
return false;
192+
if (destination_ip_addresses_not == null) {
193+
if (other.destination_ip_addresses_not != null)
194+
return false;
195+
} else if (!destination_ip_addresses_not
196+
.equals(other.destination_ip_addresses_not))
197+
return false;
198+
if (destination_port_max == null) {
199+
if (other.destination_port_max != null)
200+
return false;
201+
} else if (!destination_port_max.equals(other.destination_port_max))
202+
return false;
203+
if (destination_port_min == null) {
204+
if (other.destination_port_min != null)
205+
return false;
206+
} else if (!destination_port_min.equals(other.destination_port_min))
207+
return false;
208+
if (destination_port_not == null) {
209+
if (other.destination_port_not != null)
210+
return false;
211+
} else if (!destination_port_not.equals(other.destination_port_not))
212+
return false;
213+
if (ethertype == null) {
214+
if (other.ethertype != null)
215+
return false;
216+
} else if (!ethertype.equals(other.ethertype))
217+
return false;
218+
if (protocol == null) {
219+
if (other.protocol != null)
220+
return false;
221+
} else if (!protocol.equals(other.protocol))
222+
return false;
223+
if (source_ip_addresses == null) {
224+
if (other.source_ip_addresses != null)
225+
return false;
226+
} else if (!source_ip_addresses.equals(other.source_ip_addresses))
227+
return false;
228+
if (source_ip_addresses_not == null) {
229+
if (other.source_ip_addresses_not != null)
230+
return false;
231+
} else if (!source_ip_addresses_not
232+
.equals(other.source_ip_addresses_not))
233+
return false;
234+
if (source_port_max == null) {
235+
if (other.source_port_max != null)
236+
return false;
237+
} else if (!source_port_max.equals(other.source_port_max))
238+
return false;
239+
if (source_port_min == null) {
240+
if (other.source_port_min != null)
241+
return false;
242+
} else if (!source_port_min.equals(other.source_port_min))
243+
return false;
244+
if (source_port_not == null) {
245+
if (other.source_port_not != null)
246+
return false;
247+
} else if (!source_port_not.equals(other.source_port_not))
248+
return false;
249+
return true;
250+
}
131251

132252

133253
}

‎plugins/network-elements/nicira-nvp/src/com/cloud/network/nicira/NatRule.java‎

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,4 +110,114 @@ public void setToDestinationPort(Integer to_destination_port) {
110110
public String getType() {
111111
return type;
112112
}
113+
114+
public void setType(String type) {
115+
this.type = type;
116+
}
117+
118+
@Override
119+
public int hashCode() {
120+
final int prime = 42;
121+
int result = 1;
122+
result = prime * result + ((match == null) ? 0 : match.hashCode());
123+
result = prime
124+
* result
125+
+ ((to_destination_ip_address_max == null) ? 0
126+
: to_destination_ip_address_max.hashCode());
127+
result = prime
128+
* result
129+
+ ((to_destination_ip_address_min == null) ? 0
130+
: to_destination_ip_address_min.hashCode());
131+
result = prime
132+
* result
133+
+ ((to_destination_port == null) ? 0 : to_destination_port
134+
.hashCode());
135+
result = prime
136+
* result
137+
+ ((to_source_ip_address_max == null) ? 0
138+
: to_source_ip_address_max.hashCode());
139+
result = prime
140+
* result
141+
+ ((to_source_ip_address_min == null) ? 0
142+
: to_source_ip_address_min.hashCode());
143+
result = prime
144+
* result
145+
+ ((to_source_port_max == null) ? 0 : to_source_port_max
146+
.hashCode());
147+
result = prime
148+
* result
149+
+ ((to_source_port_min == null) ? 0 : to_source_port_min
150+
.hashCode());
151+
result = prime * result + ((type == null) ? 0 : type.hashCode());
152+
result = prime * result + ((uuid == null) ? 0 : uuid.hashCode());
153+
return result;
154+
}
155+
156+
@Override
157+
public boolean equals(Object obj) {
158+
if (this == obj)
159+
return true;
160+
if (obj == null)
161+
return false;
162+
if (getClass() != obj.getClass())
163+
return false;
164+
NatRule other = (NatRule) obj;
165+
if (match == null) {
166+
if (other.match != null)
167+
return false;
168+
} else if (!match.equals(other.match))
169+
return false;
170+
if (to_destination_ip_address_max == null) {
171+
if (other.to_destination_ip_address_max != null)
172+
return false;
173+
} else if (!to_destination_ip_address_max
174+
.equals(other.to_destination_ip_address_max))
175+
return false;
176+
if (to_destination_ip_address_min == null) {
177+
if (other.to_destination_ip_address_min != null)
178+
return false;
179+
} else if (!to_destination_ip_address_min
180+
.equals(other.to_destination_ip_address_min))
181+
return false;
182+
if (to_destination_port == null) {
183+
if (other.to_destination_port != null)
184+
return false;
185+
} else if (!to_destination_port.equals(other.to_destination_port))
186+
return false;
187+
if (to_source_ip_address_max == null) {
188+
if (other.to_source_ip_address_max != null)
189+
return false;
190+
} else if (!to_source_ip_address_max
191+
.equals(other.to_source_ip_address_max))
192+
return false;
193+
if (to_source_ip_address_min == null) {
194+
if (other.to_source_ip_address_min != null)
195+
return false;
196+
} else if (!to_source_ip_address_min
197+
.equals(other.to_source_ip_address_min))
198+
return false;
199+
if (to_source_port_max == null) {
200+
if (other.to_source_port_max != null)
201+
return false;
202+
} else if (!to_source_port_max.equals(other.to_source_port_max))
203+
return false;
204+
if (to_source_port_min == null) {
205+
if (other.to_source_port_min != null)
206+
return false;
207+
} else if (!to_source_port_min.equals(other.to_source_port_min))
208+
return false;
209+
if (type == null) {
210+
if (other.type != null)
211+
return false;
212+
} else if (!type.equals(other.type))
213+
return false;
214+
if (uuid == null) {
215+
if (other.uuid != null)
216+
return false;
217+
} else if (!uuid.equals(other.uuid))
218+
return false;
219+
return true;
220+
}
221+
222+
113223
}

‎plugins/network-elements/nicira-nvp/src/com/cloud/network/nicira/NiciraNvpApi.java‎

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -240,14 +240,7 @@ public void modifyLogicalRouterPortAttachment(String logicalRouterUuid, String l
240240
public NatRule createLogicalRouterNatRule(String logicalRouterUuid, NatRule natRule) throws NiciraNvpApiException {
241241
String uri = "/ws.v1/lrouter/" + logicalRouterUuid + "/nat";
242242

243-
if (natRule instanceof SourceNatRule) {
244-
return executeCreateObject(natRule, new TypeToken<SourceNatRule>(){}.getType(), uri, Collections.<String,String>emptyMap());
245-
}
246-
else if (natRule instanceof DestinationNatRule) {
247-
return executeCreateObject(natRule, new TypeToken<DestinationNatRule>(){}.getType(), uri, Collections.<String,String>emptyMap());
248-
}
249-
250-
throw new NiciraNvpApiException("Unknown NatRule type");
243+
return executeCreateObject(natRule, new TypeToken<NatRule>(){}.getType(), uri, Collections.<String,String>emptyMap());
251244
}
252245

253246
public void modifyLogicalRouterNatRule(String logicalRouterUuid, NatRule natRule) throws NiciraNvpApiException {

‎plugins/network-elements/nicira-nvp/src/com/cloud/network/nicira/SourceNatRule.java‎

Lines changed: 0 additions & 27 deletions
This file was deleted.

0 commit comments

Comments
 (0)