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 @@
*/
package org.onosproject.openstackswitching;
import java.util.Collection;
import static com.google.common.base.Preconditions.checkNotNull;
......@@ -28,6 +30,7 @@ public final class OpenstackNetwork {
private String segmentId;
private String id;
private NetworkType networkType;
private Collection<OpenstackSubnet> subnets;
public enum NetworkType {
/**
......@@ -49,12 +52,13 @@ public final class OpenstackNetwork {
}
private OpenstackNetwork(String name, String tenantId, String id, String sid,
NetworkType type) {
NetworkType type, Collection<OpenstackSubnet> subnets) {
this.name = checkNotNull(name);
this.tenantId = checkNotNull(tenantId);
this.segmentId = checkNotNull(sid);
this.id = checkNotNull(id);
this.networkType = type;
this.subnets = subnets;
}
public String name() {
......@@ -77,6 +81,10 @@ public final class OpenstackNetwork {
return this.networkType;
}
public Collection<OpenstackSubnet> subnets() {
return this.subnets;
}
@Override
protected Object clone() throws CloneNotSupportedException {
return super.clone();
......@@ -88,6 +96,7 @@ public final class OpenstackNetwork {
private String id;
private String sid;
private NetworkType networkType;
private Collection<OpenstackSubnet> subnets;
public Builder name(String name) {
this.name = name;
......@@ -119,9 +128,14 @@ public final class OpenstackNetwork {
return this;
}
public OpenstackNetwork build() {
return new OpenstackNetwork(name, tenantId, id, sid, networkType);
public Builder subnets(Collection<OpenstackSubnet> subnets) {
this.subnets = subnets;
return this;
}
public OpenstackNetwork build() {
return new OpenstackNetwork(name, tenantId, id, sid, networkType, subnets);
}
}
}
......
......@@ -86,8 +86,16 @@ public interface OpenstackSwitchingService {
* Returns network information list for the network ID given.
*
* @param networkId Network ID
* @return network information list
* @return network information list, or null if not present
*/
OpenstackNetwork network(String networkId);
/**
* Returns subnet information for the subnet ID give.
*
* @param subnetId Subnet ID
* @return subnet information, or null if not present
*/
OpenstackSubnet subnet(String subnetId);
}
......
......@@ -210,10 +210,41 @@ public class OpenstackSwitchingManager implements OpenstackSwitchingService {
@Override
public OpenstackNetwork network(String networkId) {
Collection<OpenstackNetwork> networks = restHandler.getNetworks();
return networks.stream()
.filter(n -> n.id().equals(networkId))
.findFirst().orElse(null);
try {
Collection<OpenstackSubnet> subnets = restHandler.getSubnets().stream()
.filter(s -> s.networkId().equals(networkId))
.collect(Collectors.toList());
Collection<OpenstackNetwork> networks = restHandler.getNetworks();
OpenstackNetwork openstackNetwork = networks.stream()
.filter(n -> n.id().equals(networkId))
.findFirst().get();
return OpenstackNetwork.builder()
.id(openstackNetwork.id())
.name(openstackNetwork.name())
.networkType(openstackNetwork.networkType())
.segmentId(openstackNetwork.segmentId())
.tenantId(openstackNetwork.tenantId())
.subnets(subnets)
.build();
} catch (NoSuchElementException e) {
log.warn("There is no network infor for net ID {}", networkId);
return null;
}
}
@Override
public OpenstackSubnet subnet(String subnetId) {
Collection<OpenstackSubnet> subnets = restHandler.getSubnets();
try {
return subnets.stream()
.filter(s -> s.id().equals(subnetId))
.findFirst().get();
} catch (NoSuchElementException e) {
log.warn("There is no subnet info for subnet ID {}", subnetId);
return null;
}
}
private void processDeviceAdded(Device device) {
......