sanghoshin
Committed by Gerrit Code Review

[SONA] OpenstackSwitching : network() and subnet()

- Added subnet information to OpenstackNetwork class
- Added a new interface, subnet() to return the subnet information.

Change-Id: Ib46455b297909275ba36659efaee2320a111a65e
...@@ -15,6 +15,8 @@ ...@@ -15,6 +15,8 @@
15 */ 15 */
16 package org.onosproject.openstackswitching; 16 package org.onosproject.openstackswitching;
17 17
18 +import java.util.Collection;
19 +
18 import static com.google.common.base.Preconditions.checkNotNull; 20 import static com.google.common.base.Preconditions.checkNotNull;
19 21
20 22
...@@ -28,6 +30,7 @@ public final class OpenstackNetwork { ...@@ -28,6 +30,7 @@ public final class OpenstackNetwork {
28 private String segmentId; 30 private String segmentId;
29 private String id; 31 private String id;
30 private NetworkType networkType; 32 private NetworkType networkType;
33 + private Collection<OpenstackSubnet> subnets;
31 34
32 public enum NetworkType { 35 public enum NetworkType {
33 /** 36 /**
...@@ -49,12 +52,13 @@ public final class OpenstackNetwork { ...@@ -49,12 +52,13 @@ public final class OpenstackNetwork {
49 } 52 }
50 53
51 private OpenstackNetwork(String name, String tenantId, String id, String sid, 54 private OpenstackNetwork(String name, String tenantId, String id, String sid,
52 - NetworkType type) { 55 + NetworkType type, Collection<OpenstackSubnet> subnets) {
53 this.name = checkNotNull(name); 56 this.name = checkNotNull(name);
54 this.tenantId = checkNotNull(tenantId); 57 this.tenantId = checkNotNull(tenantId);
55 this.segmentId = checkNotNull(sid); 58 this.segmentId = checkNotNull(sid);
56 this.id = checkNotNull(id); 59 this.id = checkNotNull(id);
57 this.networkType = type; 60 this.networkType = type;
61 + this.subnets = subnets;
58 } 62 }
59 63
60 public String name() { 64 public String name() {
...@@ -77,6 +81,10 @@ public final class OpenstackNetwork { ...@@ -77,6 +81,10 @@ public final class OpenstackNetwork {
77 return this.networkType; 81 return this.networkType;
78 } 82 }
79 83
84 + public Collection<OpenstackSubnet> subnets() {
85 + return this.subnets;
86 + }
87 +
80 @Override 88 @Override
81 protected Object clone() throws CloneNotSupportedException { 89 protected Object clone() throws CloneNotSupportedException {
82 return super.clone(); 90 return super.clone();
...@@ -88,6 +96,7 @@ public final class OpenstackNetwork { ...@@ -88,6 +96,7 @@ public final class OpenstackNetwork {
88 private String id; 96 private String id;
89 private String sid; 97 private String sid;
90 private NetworkType networkType; 98 private NetworkType networkType;
99 + private Collection<OpenstackSubnet> subnets;
91 100
92 public Builder name(String name) { 101 public Builder name(String name) {
93 this.name = name; 102 this.name = name;
...@@ -119,9 +128,14 @@ public final class OpenstackNetwork { ...@@ -119,9 +128,14 @@ public final class OpenstackNetwork {
119 return this; 128 return this;
120 } 129 }
121 130
122 - public OpenstackNetwork build() { 131 + public Builder subnets(Collection<OpenstackSubnet> subnets) {
123 - return new OpenstackNetwork(name, tenantId, id, sid, networkType); 132 + this.subnets = subnets;
133 +
134 + return this;
124 } 135 }
125 136
137 + public OpenstackNetwork build() {
138 + return new OpenstackNetwork(name, tenantId, id, sid, networkType, subnets);
139 + }
126 } 140 }
127 } 141 }
......
...@@ -86,8 +86,16 @@ public interface OpenstackSwitchingService { ...@@ -86,8 +86,16 @@ public interface OpenstackSwitchingService {
86 * Returns network information list for the network ID given. 86 * Returns network information list for the network ID given.
87 * 87 *
88 * @param networkId Network ID 88 * @param networkId Network ID
89 - * @return network information list 89 + * @return network information list, or null if not present
90 */ 90 */
91 OpenstackNetwork network(String networkId); 91 OpenstackNetwork network(String networkId);
92 92
93 +
94 + /**
95 + * Returns subnet information for the subnet ID give.
96 + *
97 + * @param subnetId Subnet ID
98 + * @return subnet information, or null if not present
99 + */
100 + OpenstackSubnet subnet(String subnetId);
93 } 101 }
......
...@@ -210,10 +210,41 @@ public class OpenstackSwitchingManager implements OpenstackSwitchingService { ...@@ -210,10 +210,41 @@ public class OpenstackSwitchingManager implements OpenstackSwitchingService {
210 210
211 @Override 211 @Override
212 public OpenstackNetwork network(String networkId) { 212 public OpenstackNetwork network(String networkId) {
213 - Collection<OpenstackNetwork> networks = restHandler.getNetworks(); 213 + try {
214 - return networks.stream() 214 + Collection<OpenstackSubnet> subnets = restHandler.getSubnets().stream()
215 - .filter(n -> n.id().equals(networkId)) 215 + .filter(s -> s.networkId().equals(networkId))
216 - .findFirst().orElse(null); 216 + .collect(Collectors.toList());
217 +
218 + Collection<OpenstackNetwork> networks = restHandler.getNetworks();
219 + OpenstackNetwork openstackNetwork = networks.stream()
220 + .filter(n -> n.id().equals(networkId))
221 + .findFirst().get();
222 +
223 + return OpenstackNetwork.builder()
224 + .id(openstackNetwork.id())
225 + .name(openstackNetwork.name())
226 + .networkType(openstackNetwork.networkType())
227 + .segmentId(openstackNetwork.segmentId())
228 + .tenantId(openstackNetwork.tenantId())
229 + .subnets(subnets)
230 + .build();
231 + } catch (NoSuchElementException e) {
232 + log.warn("There is no network infor for net ID {}", networkId);
233 + return null;
234 + }
235 + }
236 +
237 + @Override
238 + public OpenstackSubnet subnet(String subnetId) {
239 + Collection<OpenstackSubnet> subnets = restHandler.getSubnets();
240 + try {
241 + return subnets.stream()
242 + .filter(s -> s.id().equals(subnetId))
243 + .findFirst().get();
244 + } catch (NoSuchElementException e) {
245 + log.warn("There is no subnet info for subnet ID {}", subnetId);
246 + return null;
247 + }
217 } 248 }
218 249
219 private void processDeviceAdded(Device device) { 250 private void processDeviceAdded(Device device) {
......