Committed by
Gerrit Code Review
Support allowed_address_pairs
Change-Id: Id897c1833e18d1b3885394159f6beae240b3f52b
Showing
2 changed files
with
53 additions
and
35 deletions
... | @@ -15,12 +15,14 @@ | ... | @@ -15,12 +15,14 @@ |
15 | */ | 15 | */ |
16 | package org.onosproject.openstackswitching; | 16 | package org.onosproject.openstackswitching; |
17 | 17 | ||
18 | +import com.google.common.collect.Maps; | ||
18 | import org.onlab.packet.Ip4Address; | 19 | import org.onlab.packet.Ip4Address; |
20 | +import org.onlab.packet.IpAddress; | ||
19 | import org.onlab.packet.MacAddress; | 21 | import org.onlab.packet.MacAddress; |
20 | 22 | ||
21 | import java.util.Collection; | 23 | import java.util.Collection; |
22 | -import java.util.Collections; | ||
23 | import java.util.HashMap; | 24 | import java.util.HashMap; |
25 | +import java.util.Map; | ||
24 | 26 | ||
25 | import static com.google.common.base.Preconditions.checkNotNull; | 27 | import static com.google.common.base.Preconditions.checkNotNull; |
26 | 28 | ||
... | @@ -38,8 +40,7 @@ public final class OpenstackPort { | ... | @@ -38,8 +40,7 @@ public final class OpenstackPort { |
38 | 40 | ||
39 | private PortStatus status; | 41 | private PortStatus status; |
40 | private String name; | 42 | private String name; |
41 | - // FIX_ME | 43 | + private Map<IpAddress, MacAddress> allowedAddressPairs; |
42 | - private String allowedAddressPairs; | ||
43 | private boolean adminStateUp; | 44 | private boolean adminStateUp; |
44 | private String networkId; | 45 | private String networkId; |
45 | private String tenantId; | 46 | private String tenantId; |
... | @@ -51,13 +52,13 @@ public final class OpenstackPort { | ... | @@ -51,13 +52,13 @@ public final class OpenstackPort { |
51 | private Collection<String> securityGroups; | 52 | private Collection<String> securityGroups; |
52 | private String deviceId; | 53 | private String deviceId; |
53 | 54 | ||
54 | - private OpenstackPort(PortStatus status, String name, boolean adminStateUp, | 55 | + private OpenstackPort(PortStatus status, String name, Map<IpAddress, MacAddress> allowedAddressPairs, |
55 | - String networkId, String tenantId, String deviceOwner, | 56 | + boolean adminStateUp, String networkId, String tenantId, |
56 | - MacAddress macAddress, HashMap fixedIps, String id, | 57 | + String deviceOwner, MacAddress macAddress, HashMap fixedIps, |
57 | - Collection<String> securityGroups, String deviceId) { | 58 | + String id, Collection<String> securityGroups, String deviceId) { |
58 | - | ||
59 | this.status = status; | 59 | this.status = status; |
60 | this.name = name; | 60 | this.name = name; |
61 | + this.allowedAddressPairs = checkNotNull(allowedAddressPairs); | ||
61 | this.adminStateUp = adminStateUp; | 62 | this.adminStateUp = adminStateUp; |
62 | this.networkId = checkNotNull(networkId); | 63 | this.networkId = checkNotNull(networkId); |
63 | this.tenantId = checkNotNull(tenantId); | 64 | this.tenantId = checkNotNull(tenantId); |
... | @@ -99,6 +100,15 @@ public final class OpenstackPort { | ... | @@ -99,6 +100,15 @@ public final class OpenstackPort { |
99 | } | 100 | } |
100 | 101 | ||
101 | /** | 102 | /** |
103 | + * Returns allowed address pairs. | ||
104 | + * | ||
105 | + * @return map of ip address and mac address, or empty map | ||
106 | + */ | ||
107 | + public Map<IpAddress, MacAddress> allowedAddressPairs() { | ||
108 | + return allowedAddressPairs; | ||
109 | + } | ||
110 | + | ||
111 | + /** | ||
102 | * Returns whether admin state up or not. | 112 | * Returns whether admin state up or not. |
103 | * | 113 | * |
104 | * @return true if admin state up, false otherwise | 114 | * @return true if admin state up, false otherwise |
... | @@ -170,27 +180,6 @@ public final class OpenstackPort { | ... | @@ -170,27 +180,6 @@ public final class OpenstackPort { |
170 | return deviceId; | 180 | return deviceId; |
171 | } | 181 | } |
172 | 182 | ||
173 | - // TODO : Implement the following functions when necessary | ||
174 | - //@Override | ||
175 | - //public void equals(Object that) { | ||
176 | - // | ||
177 | - //} | ||
178 | - // | ||
179 | - //@Override | ||
180 | - //public int hashCode() { | ||
181 | - // | ||
182 | - //} | ||
183 | - | ||
184 | - @Override | ||
185 | - public Object clone() { | ||
186 | - OpenstackPort op = new OpenstackPort(this.status, this.name, this.adminStateUp, | ||
187 | - this.networkId, this.tenantId, this.deviceOwner, this.macAddress, | ||
188 | - (HashMap) this.fixedIps.clone(), this.id, | ||
189 | - Collections.unmodifiableCollection(this.securityGroups), this.deviceId); | ||
190 | - | ||
191 | - return op; | ||
192 | - } | ||
193 | - | ||
194 | /** | 183 | /** |
195 | * OpenstackPort Builder class. | 184 | * OpenstackPort Builder class. |
196 | */ | 185 | */ |
... | @@ -198,8 +187,7 @@ public final class OpenstackPort { | ... | @@ -198,8 +187,7 @@ public final class OpenstackPort { |
198 | 187 | ||
199 | private PortStatus status; | 188 | private PortStatus status; |
200 | private String name; | 189 | private String name; |
201 | - // FIX_ME | 190 | + private Map<IpAddress, MacAddress> allowedAddressPairs; |
202 | - private String allowedAddressPairs; | ||
203 | private boolean adminStateUp; | 191 | private boolean adminStateUp; |
204 | private String networkId; | 192 | private String networkId; |
205 | private String tenantId; | 193 | private String tenantId; |
... | @@ -212,7 +200,8 @@ public final class OpenstackPort { | ... | @@ -212,7 +200,8 @@ public final class OpenstackPort { |
212 | private String deviceId; | 200 | private String deviceId; |
213 | 201 | ||
214 | Builder() { | 202 | Builder() { |
215 | - fixedIps = new HashMap<>(); | 203 | + fixedIps = Maps.newHashMap(); |
204 | + allowedAddressPairs = Maps.newHashMap(); | ||
216 | } | 205 | } |
217 | 206 | ||
218 | /** | 207 | /** |
... | @@ -240,6 +229,17 @@ public final class OpenstackPort { | ... | @@ -240,6 +229,17 @@ public final class OpenstackPort { |
240 | } | 229 | } |
241 | 230 | ||
242 | /** | 231 | /** |
232 | + * Sets allowed address pairs. | ||
233 | + * | ||
234 | + * @param addrPairs map of ip address and mac address | ||
235 | + * @return Builder object | ||
236 | + */ | ||
237 | + public Builder allowedAddressPairs(Map<IpAddress, MacAddress> addrPairs) { | ||
238 | + this.allowedAddressPairs.putAll(addrPairs); | ||
239 | + return this; | ||
240 | + } | ||
241 | + | ||
242 | + /** | ||
243 | * Sets whether admin state up or not. | 243 | * Sets whether admin state up or not. |
244 | * | 244 | * |
245 | * @param isAdminStateUp true if admin state is up, false otherwise | 245 | * @param isAdminStateUp true if admin state is up, false otherwise |
... | @@ -352,8 +352,9 @@ public final class OpenstackPort { | ... | @@ -352,8 +352,9 @@ public final class OpenstackPort { |
352 | * @return OpenstackPort objecet | 352 | * @return OpenstackPort objecet |
353 | */ | 353 | */ |
354 | public OpenstackPort build() { | 354 | public OpenstackPort build() { |
355 | - return new OpenstackPort(status, name, adminStateUp, networkId, networkId, | 355 | + return new OpenstackPort(status, name, allowedAddressPairs, adminStateUp, |
356 | - deviceOwner, macAddress, fixedIps, id, securityGroups, deviceId); | 356 | + networkId, networkId, deviceOwner, macAddress, fixedIps, |
357 | + id, securityGroups, deviceId); | ||
357 | } | 358 | } |
358 | } | 359 | } |
359 | } | 360 | } | ... | ... |
... | @@ -19,7 +19,9 @@ import com.fasterxml.jackson.databind.JsonNode; | ... | @@ -19,7 +19,9 @@ import com.fasterxml.jackson.databind.JsonNode; |
19 | import com.fasterxml.jackson.databind.node.ArrayNode; | 19 | import com.fasterxml.jackson.databind.node.ArrayNode; |
20 | import com.fasterxml.jackson.databind.node.ObjectNode; | 20 | import com.fasterxml.jackson.databind.node.ObjectNode; |
21 | import com.google.common.collect.Lists; | 21 | import com.google.common.collect.Lists; |
22 | +import com.google.common.collect.Maps; | ||
22 | import org.onlab.packet.Ip4Address; | 23 | import org.onlab.packet.Ip4Address; |
24 | +import org.onlab.packet.IpAddress; | ||
23 | import org.onlab.packet.MacAddress; | 25 | import org.onlab.packet.MacAddress; |
24 | import org.onosproject.codec.CodecContext; | 26 | import org.onosproject.codec.CodecContext; |
25 | import org.onosproject.codec.JsonCodec; | 27 | import org.onosproject.codec.JsonCodec; |
... | @@ -29,6 +31,7 @@ import org.slf4j.LoggerFactory; | ... | @@ -29,6 +31,7 @@ import org.slf4j.LoggerFactory; |
29 | 31 | ||
30 | import java.util.Collection; | 32 | import java.util.Collection; |
31 | import java.util.HashMap; | 33 | import java.util.HashMap; |
34 | +import java.util.Map; | ||
32 | 35 | ||
33 | /** | 36 | /** |
34 | * Encodes and decodes the OpenstackPort. | 37 | * Encodes and decodes the OpenstackPort. |
... | @@ -54,6 +57,7 @@ public class OpenstackPortCodec extends JsonCodec<OpenstackPort> { | ... | @@ -54,6 +57,7 @@ public class OpenstackPortCodec extends JsonCodec<OpenstackPort> { |
54 | private static final String ID = "id"; | 57 | private static final String ID = "id"; |
55 | private static final String SECURITY_GROUPS = "security_groups"; | 58 | private static final String SECURITY_GROUPS = "security_groups"; |
56 | private static final String DEVICE_ID = "device_id"; | 59 | private static final String DEVICE_ID = "device_id"; |
60 | + private static final String NA = "N/A"; | ||
57 | 61 | ||
58 | @Override | 62 | @Override |
59 | public OpenstackPort decode(ObjectNode json, CodecContext context) { | 63 | public OpenstackPort decode(ObjectNode json, CodecContext context) { |
... | @@ -86,9 +90,19 @@ public class OpenstackPortCodec extends JsonCodec<OpenstackPort> { | ... | @@ -86,9 +90,19 @@ public class OpenstackPortCodec extends JsonCodec<OpenstackPort> { |
86 | securityGroupList.forEach(securityGroup -> securityGroupIdList.add(securityGroup.asText())); | 90 | securityGroupList.forEach(securityGroup -> securityGroupIdList.add(securityGroup.asText())); |
87 | String deviceId = portInfo.path(DEVICE_ID).asText(); | 91 | String deviceId = portInfo.path(DEVICE_ID).asText(); |
88 | 92 | ||
93 | + Map<IpAddress, MacAddress> addressPairs = Maps.newHashMap(); | ||
94 | + for (JsonNode addrPair : (ArrayNode) portInfo.path(ADDRESS_PAIR)) { | ||
95 | + try { | ||
96 | + addressPairs.put(IpAddress.valueOf(addrPair.path(IP_ADDRESS).asText()), | ||
97 | + MacAddress.valueOf(addrPair.path(MAC_ADDRESS).asText())); | ||
98 | + } catch (IllegalArgumentException e) { | ||
99 | + log.debug("Invalid address pair {}", addrPair.toString()); | ||
100 | + } | ||
101 | + } | ||
102 | + | ||
89 | OpenstackPort.Builder openstackPortBuilder = OpenstackPort.builder(); | 103 | OpenstackPort.Builder openstackPortBuilder = OpenstackPort.builder(); |
90 | OpenstackPort.PortStatus portStatus = | 104 | OpenstackPort.PortStatus portStatus = |
91 | - status.equals("N/A") ? OpenstackPort.PortStatus.NA : | 105 | + status.equals(NA) ? OpenstackPort.PortStatus.NA : |
92 | OpenstackPort.PortStatus.valueOf(status); | 106 | OpenstackPort.PortStatus.valueOf(status); |
93 | 107 | ||
94 | openstackPortBuilder.portStatus(portStatus) | 108 | openstackPortBuilder.portStatus(portStatus) |
... | @@ -103,6 +117,9 @@ public class OpenstackPortCodec extends JsonCodec<OpenstackPort> { | ... | @@ -103,6 +117,9 @@ public class OpenstackPortCodec extends JsonCodec<OpenstackPort> { |
103 | .deviceId(deviceId) | 117 | .deviceId(deviceId) |
104 | .securityGroup(securityGroupIdList); | 118 | .securityGroup(securityGroupIdList); |
105 | 119 | ||
120 | + if (!addressPairs.isEmpty()) { | ||
121 | + openstackPortBuilder.allowedAddressPairs(addressPairs); | ||
122 | + } | ||
106 | 123 | ||
107 | OpenstackPort openstackPort = openstackPortBuilder.build(); | 124 | OpenstackPort openstackPort = openstackPortBuilder.build(); |
108 | 125 | ... | ... |
-
Please register or login to post a comment