Sho SHIMIZU

Apply more functional style

Change-Id: Ib2194054dcddbc975f426c5a17a89031e3b1166d
......@@ -16,8 +16,8 @@
package org.onosproject.driver.ovsdb;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
import java.util.stream.Collectors;
import org.onlab.packet.IpAddress;
import org.onosproject.net.DeviceId;
......@@ -36,8 +36,6 @@ import org.onosproject.ovsdb.controller.OvsdbController;
import org.onosproject.ovsdb.controller.OvsdbNodeId;
import org.onosproject.ovsdb.controller.OvsdbPort;
import com.google.common.collect.Sets;
/**
* The implementation of BridageConfig.
*/
......@@ -63,18 +61,16 @@ public class OvsdbBridgeConfig extends AbstractHandlerBehaviour
DriverHandler handler = handler();
DeviceId deviceId = handler.data().deviceId();
OvsdbClientService clientService = getOvsdbClientService(handler);
Set<OvsdbBridge> ovsdbSet = clientService.getBridges();
Collection<BridgeDescription> bridges = Sets.newHashSet();
ovsdbSet.forEach(o -> {
BridgeName bridgeName = BridgeName
.bridgeName(o.bridgeName().value());
DeviceId ownDeviceId = DeviceId.deviceId("of:" + o.datapathId().value());
BridgeDescription description = new DefaultBridgeDescription(bridgeName,
deviceId,
ownDeviceId);
bridges.add(description);
});
return bridges;
Set<OvsdbBridge> bridges = clientService.getBridges();
return bridges.stream()
.map(x -> new DefaultBridgeDescription(
BridgeName.bridgeName(x.bridgeName().value()),
deviceId,
DeviceId.deviceId("of:" + x.datapathId().value())
)
)
.collect(Collectors.toSet());
}
@Override
......@@ -105,14 +101,15 @@ public class OvsdbBridgeConfig extends AbstractHandlerBehaviour
public Collection<PortDescription> getPorts() {
DriverHandler handler = handler();
OvsdbClientService clientService = getOvsdbClientService(handler);
Set<OvsdbPort> ovsdbSet = clientService.getPorts();
Collection<PortDescription> ports = Sets.newHashSet();
ovsdbSet.forEach(o -> {
PortNumber port = PortNumber.portNumber(o.portNumber().value());
PortDescription description = new DefaultPortDescription(port, true);
ports.add(description);
});
return ports;
Set<OvsdbPort> ports = clientService.getPorts();
return ports.stream()
.map(x -> new DefaultPortDescription(
PortNumber.portNumber(x.portNumber().value()),
true
)
)
.collect(Collectors.toSet());
}
// OvsdbNodeId(IP:port) is used in the adaptor while DeviceId(ovsdb:IP:port)
......@@ -137,15 +134,16 @@ public class OvsdbBridgeConfig extends AbstractHandlerBehaviour
@Override
public Set<PortNumber> getPortNumbers() {
Set<PortNumber> ports = new HashSet<>();
DriverHandler handler = handler();
OvsdbClientService clientService = getOvsdbClientService(handler);
Set<OvsdbPort> ovsdbSet = clientService.getPorts();
ovsdbSet.forEach(o -> {
PortNumber port = PortNumber.portNumber(o.portNumber().value(),
o.portName().value());
ports.add(port);
});
return ports;
Set<OvsdbPort> ports = clientService.getPorts();
return ports.stream()
.map(x -> PortNumber.portNumber(
x.portNumber().value(),
x.portName().value()
)
)
.collect(Collectors.toSet());
}
}
......
......@@ -18,6 +18,7 @@ package org.onosproject.driver.ovsdb;
import java.util.Collection;
import java.util.Set;
import java.util.stream.Collectors;
import org.onlab.packet.IpAddress;
import org.onosproject.net.DeviceId;
......@@ -25,7 +26,6 @@ import org.onosproject.net.behaviour.DefaultTunnelDescription;
import org.onosproject.net.behaviour.IpTunnelEndPoint;
import org.onosproject.net.behaviour.TunnelConfig;
import org.onosproject.net.behaviour.TunnelDescription;
import org.onosproject.net.behaviour.TunnelEndPoint;
import org.onosproject.net.behaviour.TunnelName;
import org.onosproject.net.driver.AbstractHandlerBehaviour;
import org.onosproject.net.driver.DriverHandler;
......@@ -34,8 +34,6 @@ import org.onosproject.ovsdb.controller.OvsdbController;
import org.onosproject.ovsdb.controller.OvsdbNodeId;
import org.onosproject.ovsdb.controller.OvsdbTunnel;
import com.google.common.collect.Sets;
/**
* OVSDB-based implementation of tunnel config behaviour.
*/
......@@ -90,20 +88,18 @@ public class OvsdbTunnelConfig extends AbstractHandlerBehaviour
public Collection<TunnelDescription> getTunnels() {
DriverHandler handler = handler();
OvsdbClientService ovsdbNode = getOvsdbNode(handler);
Set<OvsdbTunnel> ovsdbSet = ovsdbNode.getTunnels();
Collection<TunnelDescription> tunnels = Sets.newHashSet();
ovsdbSet.forEach(o -> {
TunnelEndPoint ipSrc = IpTunnelEndPoint.ipTunnelPoint(o.localIp());
TunnelEndPoint ipDst = IpTunnelEndPoint.ipTunnelPoint(o.remoteIp());
TunnelName name = TunnelName.tunnelName(o.tunnelName().toString());
TunnelDescription des = new DefaultTunnelDescription(
ipSrc,
ipDst,
TunnelDescription.Type.VXLAN,
name);
tunnels.add(des);
});
return tunnels;
Set<OvsdbTunnel> tunnels = ovsdbNode.getTunnels();
return tunnels.stream()
.map(x ->
new DefaultTunnelDescription(
IpTunnelEndPoint.ipTunnelPoint(x.localIp()),
IpTunnelEndPoint.ipTunnelPoint(x.remoteIp()),
TunnelDescription.Type.VXLAN,
TunnelName.tunnelName(x.tunnelName().toString())
)
)
.collect(Collectors.toSet());
}
// OvsdbNodeId(IP:port) is used in the adaptor while DeviceId(ovsdb:IP:port)
......