andrea
Committed by Gerrit Code Review

Inserted set and get controllers methods in ovsdb controller config

Change-Id: I791ff2ae159d0ac50beff22abda2b187913428f6
/*
* Copyright 2015 Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.cli.net;
import org.apache.karaf.shell.commands.Argument;
import org.apache.karaf.shell.commands.Command;
import org.onosproject.cli.AbstractShellCommand;
import org.onosproject.net.DeviceId;
import org.onosproject.net.behaviour.ControllerConfig;
import org.onosproject.net.driver.DriverHandler;
import org.onosproject.net.driver.DriverService;
/**
* Sets role of the controller node for the given infrastructure device.
*/
@Command(scope = "onos", name = "device-controllers",
description = "gets the list of controllers for the given infrastructure device")
public class DeviceControllersCommand extends AbstractShellCommand {
@Argument(index = 0, name = "uri", description = "Device ID",
required = true, multiValued = false)
String uri = null;
private DeviceId deviceId;
@Override
protected void execute() {
DriverService service = get(DriverService.class);
deviceId = DeviceId.deviceId(uri);
DriverHandler h = service.createHandler(deviceId);
ControllerConfig config = h.behaviour(ControllerConfig.class);
config.getControllers().forEach(c -> print(c.target()));
}
}
/*
* Copyright 2015 Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.cli.net;
import org.apache.karaf.shell.commands.Argument;
import org.apache.karaf.shell.commands.Command;
import org.onosproject.cli.AbstractShellCommand;
import org.onosproject.net.DeviceId;
import org.onosproject.net.behaviour.ControllerConfig;
import org.onosproject.net.behaviour.ControllerInfo;
import org.onosproject.net.driver.DriverHandler;
import org.onosproject.net.driver.DriverService;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
* Sets role of the controller node for the given infrastructure device.
*/
@Command(scope = "onos", name = "device-setcontrollers",
description = "sets the list of controllers for the given infrastructure device")
public class DeviceSetControllersCommand extends AbstractShellCommand {
@Argument(index = 0, name = "uri", description = "Device ID",
required = true, multiValued = false)
String uri = null;
@Argument(index = 1, name = "controllersListStrings", description = "list of " +
"controllers to set for the specified device",
required = true, multiValued = true)
String[] controllersListStrings = null;
private DeviceId deviceId;
private List<ControllerInfo> newControllers = new ArrayList<>();
@Override
protected void execute() {
Arrays.asList(controllersListStrings).forEach(
cInfoString -> newControllers.add(new ControllerInfo(cInfoString)));
DriverService service = get(DriverService.class);
deviceId = DeviceId.deviceId(uri);
DriverHandler h = service.createHandler(deviceId);
ControllerConfig config = h.behaviour(ControllerConfig.class);
print("before:");
config.getControllers().forEach(c -> print(c.target()));
config.setControllers(newControllers);
print("after:");
config.getControllers().forEach(c -> print(c.target()));
print("size %d", config.getControllers().size());
}
}
......@@ -105,6 +105,18 @@
</completers>
</command>
<command>
<action class="org.onosproject.cli.net.DeviceControllersCommand"/>
<completers>
<ref component-id="deviceIdCompleter"/>
</completers>
</command>
<command>
<action class="org.onosproject.cli.net.DeviceSetControllersCommand"/>
<completers>
<ref component-id="deviceIdCompleter"/>
</completers>
</command>
<command>
<action class="org.onosproject.cli.net.DeviceRemoveCommand"/>
<completers>
<ref component-id="deviceIdCompleter"/>
......
......@@ -15,23 +15,27 @@
*/
package org.onosproject.net.behaviour;
import org.onosproject.net.driver.HandlerBehaviour;
import java.util.List;
/**
* Device behaviour to obtain and set controllers at the device.
*/
public interface ControllerConfig {
public interface ControllerConfig extends HandlerBehaviour {
//TODO: add other controller parameters as needed.
/**
* Obtain the list of controller which are currently configured.
*
* @return a list for controller descriptions
*/
List<ControllerInfo> getControllers();
/**
* Set a list of controllers on a device.
*
* @param controllers a list of controller descriptions
*/
void setControllers(List<ControllerInfo> controllers);
......
......@@ -15,24 +15,112 @@
*/
package org.onosproject.net.behaviour;
import com.google.common.base.Preconditions;
import org.onlab.packet.IpAddress;
import java.util.Objects;
/**
* Represents information for a device to connect to a controller.
*/
public class ControllerInfo {
public final IpAddress ip;
public final int tcpPort;
private IpAddress ip = IpAddress.valueOf("0.0.0.0");
private int port = 6653;
private String type = "error";
/**
* Information for contacting the controller.
*
* @param ip the ip address
* @param tcpPort the tcp port
* @param ip the ip address
* @param port the tcp port
*/
public ControllerInfo(IpAddress ip, int tcpPort) {
public ControllerInfo(IpAddress ip, int port, String type) {
this.ip = ip;
this.tcpPort = tcpPort;
this.port = port;
this.type = type;
}
/**
* Information for contacting the controller, if some information
* is not contained in the target string because it's optional
* it's leaved as in the field declaration (default values).
*
* @param target column returned from ovsdb query
*/
public ControllerInfo(String target) {
String[] data = target.split(":");
this.type = data[0];
Preconditions.checkArgument(!data[0].contains("unix"),
"Unable to create controller info " +
"from {} because it's based " +
"on unix sockets", target);
if (data[0].startsWith("p")) {
if (data.length >= 2) {
this.port = Integer.parseInt(data[1]);
}
if (data.length == 3) {
this.ip = IpAddress.valueOf(data[2]);
}
} else {
this.ip = IpAddress.valueOf(data[1]);
if (data.length == 3) {
this.port = Integer.parseInt(data[2]);
}
}
}
/**
* Exposes the ip address of the controller.
*
* @return IpAddress ip address
*/
public IpAddress ip() {
return ip;
}
/**
* Exposes the tcp port of the controller.
*
* @return int tcp port
*/
public int port() {
return port;
}
/**
* Exposes the type of the controller connection.
*
* @return String type
*/
public String type() {
return type;
}
public String target() {
if (type.startsWith("p")) {
return type + ":" + port + ":" + ip;
} else {
return type + ":" + ip + ":" + port;
}
}
@Override
public int hashCode() {
return Objects.hash(ip, port, type);
}
@Override
public boolean equals(Object toBeCompared) {
if (toBeCompared instanceof ControllerInfo) {
ControllerInfo controllerInfo = (ControllerInfo) toBeCompared;
if (controllerInfo.type().equals(this.type)
&& controllerInfo.ip().equals(this.ip())
&& controllerInfo.port() == this.port) {
return true;
}
}
return false;
}
}
......
/*
* Copyright 2015 Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.net.behaviour;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.onlab.packet.IpAddress;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import static org.junit.Assert.*;
/**
* Test for ControllerInfo class.
*/
public class ControllerInfoTest {
@Rule
public ExpectedException thrown = ExpectedException.none();
@Test
public void tcpSslFormat() {
String target = "tcp:192.168.1.1:6653";
ControllerInfo controllerInfo = new ControllerInfo(target);
assertEquals("wrong type", controllerInfo.type(), "tcp");
assertEquals("wrong ip", controllerInfo.ip(), IpAddress.valueOf("192.168.1.1"));
assertEquals("wrong port", controllerInfo.port(), 6653);
}
@Test
public void ptcpPsslFormat() {
String target = "ptcp:6653:192.168.1.1";
ControllerInfo controllerInfo = new ControllerInfo(target);
assertEquals("wrong type", controllerInfo.type(), "ptcp");
assertEquals("wrong ip", controllerInfo.ip(), IpAddress.valueOf("192.168.1.1"));
assertEquals("wrong port", controllerInfo.port(), 6653);
}
@Test
public void unixFormat() {
String target = "unix:file";
thrown.expect(IllegalArgumentException.class);
ControllerInfo controllerInfo = new ControllerInfo(target);
assertTrue("wrong type", controllerInfo.type().contains("unix"));
assertNull("wrong ip", controllerInfo.ip());
assertEquals("wrong port", controllerInfo.port(), -1);
}
@Test
public void defaultValues() {
String target = "tcp:192.168.1.1";
ControllerInfo controllerInfo = new ControllerInfo(target);
assertEquals("wrong type", controllerInfo.type(), "tcp");
assertEquals("wrong ip", controllerInfo.ip(), IpAddress.valueOf("192.168.1.1"));
assertEquals("wrong port", controllerInfo.port(), 6653);
String target1 = "ptcp:5000:";
ControllerInfo controllerInfo2 = new ControllerInfo(target1);
assertEquals("wrong type", controllerInfo2.type(), "ptcp");
assertEquals("wrong ip", controllerInfo2.ip(), IpAddress.valueOf("0.0.0.0"));
assertEquals("wrong port", controllerInfo2.port(), 5000);
String target2 = "ptcp:";
ControllerInfo controllerInfo3 = new ControllerInfo(target2);
assertEquals("wrong type", controllerInfo3.type(), "ptcp");
assertEquals("wrong ip", controllerInfo3.ip(), IpAddress.valueOf("0.0.0.0"));
assertEquals("wrong port", controllerInfo3.port(), 6653);
}
@Test
public void testEquals() {
String target1 = "ptcp:6653:192.168.1.1";
ControllerInfo controllerInfo1 = new ControllerInfo(target1);
String target2 = "ptcp:6653:192.168.1.1";
ControllerInfo controllerInfo2 = new ControllerInfo(target2);
assertTrue("wrong equals method", controllerInfo1.equals(controllerInfo2));
}
@Test
public void testListEquals() {
String target1 = "ptcp:6653:192.168.1.1";
ControllerInfo controllerInfo1 = new ControllerInfo(target1);
String target2 = "ptcp:6653:192.168.1.1";
ControllerInfo controllerInfo2 = new ControllerInfo(target2);
String target3 = "tcp:192.168.1.1:6653";
ControllerInfo controllerInfo3 = new ControllerInfo(target3);
String target4 = "tcp:192.168.1.1:6653";
ControllerInfo controllerInfo4 = new ControllerInfo(target4);
List<ControllerInfo> list1 = new ArrayList<>(Arrays.asList(controllerInfo1, controllerInfo3));
List<ControllerInfo> list2 = new ArrayList<>(Arrays.asList(controllerInfo2, controllerInfo4));
assertTrue("wrong equals list method", list1.equals(list2));
}
}
......@@ -55,8 +55,8 @@
<dependency>
<groupId>org.onosproject</groupId>
<artifactId>onos-core-serializers</artifactId>
<version>1.4.0-SNAPSHOT</version>
</dependency>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.onosproject</groupId>
<artifactId>onos-ovsdb-api</artifactId>
......@@ -72,6 +72,25 @@
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.scr.annotations</artifactId>
</dependency>
<dependency>
<groupId>org.onosproject</groupId>
<artifactId>onos-api</artifactId>
<version>${project.version}</version>
<classifier>tests</classifier>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.onosproject</groupId>
<artifactId>onlab-junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.onosproject</groupId>
<artifactId>onos-ovsdb-api</artifactId>
<version>${project.version}</version>
<classifier>tests</classifier>
<scope>test</scope>
</dependency>
</dependencies>
<build>
......
/*
* Copyright 2015 Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.driver.ovsdb;
import org.onlab.packet.IpAddress;
import org.onlab.packet.TpPort;
import org.onosproject.net.AnnotationKeys;
import org.onosproject.net.DeviceId;
import org.onosproject.net.behaviour.ControllerConfig;
import org.onosproject.net.behaviour.ControllerInfo;
import org.onosproject.net.device.DeviceService;
import org.onosproject.net.driver.AbstractHandlerBehaviour;
import org.onosproject.net.driver.DriverHandler;
import org.onosproject.ovsdb.controller.OvsdbBridge;
import org.onosproject.ovsdb.controller.OvsdbClientService;
import org.onosproject.ovsdb.controller.OvsdbController;
import org.onosproject.ovsdb.controller.OvsdbNodeId;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import static com.google.common.base.Preconditions.checkState;
import static org.onlab.util.Tools.delay;
/**
* Implementation of controller config which allows to get and set controllers.
*/
public class OvsdbControllerConfig extends AbstractHandlerBehaviour implements ControllerConfig {
@Override
public List<ControllerInfo> getControllers() {
DriverHandler handler = handler();
OvsdbClientService clientService = getOvsdbClientService(handler);
Set<ControllerInfo> controllers = clientService.getControllers(
handler().data().deviceId());
return new ArrayList<>(controllers);
}
@Override
public void setControllers(List<ControllerInfo> controllers) {
DriverHandler handler = handler();
OvsdbClientService clientService = getOvsdbClientService(handler);
if (!clientService.getControllers(handler().data().deviceId())
.equals(controllers)) {
clientService.setControllersWithDeviceId(handler().
data().deviceId(), controllers);
}
}
// Used for getting OvsdbClientService.
private OvsdbClientService getOvsdbClientService(DriverHandler handler) {
OvsdbController ovsController = handler.get(OvsdbController.class);
DeviceService deviceService = handler.get(DeviceService.class);
DeviceId ofDeviceId = handler.data().deviceId();
String[] mgmtAddress = deviceService.getDevice(ofDeviceId)
.annotations().value(AnnotationKeys.MANAGEMENT_ADDRESS).split(":");
String targetIp = mgmtAddress[0];
TpPort targetPort = null;
if (mgmtAddress.length > 1) {
targetPort = TpPort.tpPort(Integer.parseInt(mgmtAddress[1]));
}
List<OvsdbNodeId> nodeIds = ovsController.getNodeIds().stream()
.filter(nodeId -> nodeId.getIpAddress().equals(targetIp))
.collect(Collectors.toList());
if (nodeIds.size() == 0) {
//TODO decide what port?
ovsController.connect(IpAddress.valueOf(targetIp),
targetPort == null ? TpPort.tpPort(6640) : targetPort);
delay(1000); //FIXME... connect is async
}
List<OvsdbClientService> clientServices = ovsController.getNodeIds().stream()
.filter(nodeId -> nodeId.getIpAddress().equals(targetIp))
.map(ovsController::getOvsdbClient)
.filter(cs -> cs.getBridges().stream().anyMatch(b -> dpidMatches(b, ofDeviceId)))
.collect(Collectors.toList());
checkState(clientServices.size() > 0, "No clientServices found");
//FIXME add connection to management address if null --> done ?
return clientServices.size() > 0 ? clientServices.get(0) : null;
}
private static boolean dpidMatches(OvsdbBridge bridge, DeviceId deviceId) {
String bridgeDpid = "of:" + bridge.datapathId().value();
String ofDpid = deviceId.toString();
return bridgeDpid.equals(ofDpid);
}
}
\ No newline at end of file
......@@ -30,6 +30,8 @@
manufacturer="Nicira, Inc\." hwVersion="Open vSwitch" swVersion="2\..*">
<behaviour api="org.onosproject.openflow.controller.driver.OpenFlowSwitchDriver"
impl="org.onosproject.driver.handshaker.NiciraSwitchHandshaker"/>
<behaviour api="org.onosproject.net.behaviour.ControllerConfig"
impl="org.onosproject.driver.ovsdb.OvsdbControllerConfig"/>
</driver>
<driver name="ovs-corsa" extends="ovs"
manufacturer="Corsa" hwVersion="emulation" swVersion="0.0.0">
......
/*
* Copyright 2015 Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.driver.ovsdb;
import com.google.common.collect.ImmutableMap;
import org.junit.Before;
import org.junit.Test;
import org.onosproject.net.DeviceId;
import org.onosproject.net.behaviour.ControllerConfig;
import org.onosproject.net.device.DeviceServiceAdapter;
import org.onosproject.net.driver.DefaultDriver;
import org.onosproject.net.driver.DefaultDriverData;
import org.onosproject.net.driver.DefaultDriverHandler;
import org.onosproject.ovsdb.controller.driver.OvsdbClientServiceAdapter;
import org.onosproject.ovsdb.controller.driver.OvsdbControllerAdapter;
/**
* Created by Andrea on 10/7/15.
*/
public class OvsdbControllerConfigTest {
private static final DeviceId DEVICE_ID = DeviceId.deviceId("foo");
private DefaultDriver ddc;
private DefaultDriverData data;
private DefaultDriverHandler handler;
private TestDeviceService deviceService = new TestDeviceService();
private TestOvsdbController controller = new TestOvsdbController();
private TestOvsdbClient client = new TestOvsdbClient();
private OvsdbControllerConfig controllerConfig;
@Before
public void setUp() {
controllerConfig = new OvsdbControllerConfig();
ddc = new DefaultDriver("foo.bar", null, "Circus", "lux", "1.2a",
ImmutableMap.of(ControllerConfig.class,
OvsdbControllerConfig.class),
ImmutableMap.of("foo", "bar"));
data = new DefaultDriverData(ddc, DEVICE_ID);
handler = new DefaultDriverHandler(data);
//handler.controllerConfig.setHandler(handler);
//TODO setTestService directory on handler
//TODO setup ovsdb fake controller with fake ovsdbclient
//TODO setup fake device service
}
@Test
public void testGetControllers() throws Exception {
// DriverService driverService = new Driv
// AbstractBehaviour ab = new AbstractBehaviour();
// DriverHandler handler = handler();
// List<ControllerInfo> controllersList =
// controllerConfig.getControllers(DeviceId.deviceId("0000000000000018"));
// log.info("controllers " + controllersList);
}
@Test
public void testSetControllers() throws Exception {
}
private class TestDeviceService extends DeviceServiceAdapter {
}
private class TestOvsdbController extends OvsdbControllerAdapter {
}
private class TestOvsdbClient extends OvsdbClientServiceAdapter {
}
}
\ No newline at end of file
......@@ -48,6 +48,10 @@
</dependency>
<dependency>
<groupId>org.onosproject</groupId>
<artifactId>onos-api</artifactId>
</dependency>
<dependency>
<groupId>org.onosproject</groupId>
<artifactId>onos-ovsdb-rfc</artifactId>
<version>${project.version}</version>
</dependency>
......
......@@ -15,19 +15,20 @@
*/
package org.onosproject.ovsdb.controller;
import java.util.List;
import java.util.Set;
import com.google.common.util.concurrent.ListenableFuture;
import org.onlab.packet.IpAddress;
import org.onosproject.net.DeviceId;
import org.onosproject.net.behaviour.ControllerInfo;
import org.onosproject.ovsdb.rfc.jsonrpc.OvsdbRPC;
import org.onosproject.ovsdb.rfc.message.OperationResult;
import org.onosproject.ovsdb.rfc.message.TableUpdates;
import org.onosproject.ovsdb.rfc.notation.Row;
import org.onosproject.ovsdb.rfc.notation.UUID;
import org.onosproject.ovsdb.rfc.operations.Operation;
import org.onosproject.ovsdb.rfc.schema.DatabaseSchema;
import com.google.common.util.concurrent.ListenableFuture;
import java.util.List;
import java.util.Set;
/**
* Represents to provider facing side of a node.
......@@ -85,10 +86,33 @@ public interface OvsdbClientService extends OvsdbRPC {
Set<OvsdbBridge> getBridges();
/**
* Gets controllers of the node.
*
* @return set of controllers; empty if no controller is find
*/
Set<ControllerInfo> getControllers(DeviceId openflowDeviceId);
/**
* sets the controllers of the node to the ones passed in the list.
*
* @param bridgeUuid UUid for the bridge we are settings the controls on
* @param controllers of controllers; empty if no controller is find
*/
void setControllersWithUUID(UUID bridgeUuid, List<ControllerInfo> controllers);
/**
* sets the controllers of the node to the ones passed in the list.
*
* @param deviceId deviceId for the bridge we are settings the controls on
* @param controllers of controllers; empty if no controller is find
*/
void setControllersWithDeviceId(DeviceId deviceId, List<ControllerInfo> controllers);
/**
* Creates a port.
*
* @param bridgeName bridge name
* @param portName port name
* @param portName port name
*/
void createPort(String bridgeName, String portName);
......@@ -96,7 +120,7 @@ public interface OvsdbClientService extends OvsdbRPC {
* Drops a port.
*
* @param bridgeName bridge name
* @param portName port name
* @param portName port name
*/
void dropPort(String bridgeName, String portName);
......@@ -125,7 +149,7 @@ public interface OvsdbClientService extends OvsdbRPC {
/**
* Gets the Port uuid.
*
* @param portName port name
* @param portName port name
* @param bridgeUuid bridge uuid
* @return port uuid, empty if no uuid is find
*/
......@@ -143,7 +167,7 @@ public interface OvsdbClientService extends OvsdbRPC {
/**
* Gets the Controller uuid.
*
* @param controllerName controller name
* @param controllerName controller name
* @param controllerTarget controller target
* @return controller uuid, empty if no uuid is find
*/
......@@ -169,7 +193,7 @@ public interface OvsdbClientService extends OvsdbRPC {
* Gets the ovsdb table updates.
*
* @param dbName database name
* @param id random uuid
* @param id random uuid
* @return table updates
*/
ListenableFuture<TableUpdates> monitorTables(String dbName, String id);
......@@ -177,7 +201,7 @@ public interface OvsdbClientService extends OvsdbRPC {
/**
* Gets the ovsdb config operation result.
*
* @param dbName database name
* @param dbName database name
* @param operations the list of operations
* @return operation results
*/
......@@ -187,7 +211,7 @@ public interface OvsdbClientService extends OvsdbRPC {
/**
* Gets the ovsdb database schema from local.
*
* @param dbName database name
* @param dbName database name
* @return database schema
*/
DatabaseSchema getDatabaseSchema(String dbName);
......@@ -195,9 +219,9 @@ public interface OvsdbClientService extends OvsdbRPC {
/**
* Gets the ovsdb row from the local ovsdb store.
*
* @param dbName database name
* @param dbName database name
* @param tableName table name
* @param uuid row uuid
* @param uuid row uuid
* @return row ovsdb row
*/
Row getRow(String dbName, String tableName, String uuid);
......@@ -205,19 +229,19 @@ public interface OvsdbClientService extends OvsdbRPC {
/**
* Removes the ovsdb row from the local ovsdb store.
*
* @param dbName database name
* @param dbName database name
* @param tableName table name
* @param uuid row uuid
* @param uuid row uuid
*/
void removeRow(String dbName, String tableName, String uuid);
/**
* Updates the local ovsdb store.
*
* @param dbName database name
* @param dbName database name
* @param tableName table name
* @param uuid row uuid
* @param row ovsdb row
* @param uuid row uuid
* @param row ovsdb row
*/
void updateOvsdbStore(String dbName, String tableName, String uuid, Row row);
......
/*
* Copyright 2015 Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.ovsdb.controller.driver;
import com.fasterxml.jackson.databind.JsonNode;
import com.google.common.util.concurrent.ListenableFuture;
import org.onlab.packet.IpAddress;
import org.onosproject.net.DeviceId;
import org.onosproject.net.behaviour.ControllerInfo;
import org.onosproject.ovsdb.controller.OvsdbBridge;
import org.onosproject.ovsdb.controller.OvsdbClientService;
import org.onosproject.ovsdb.controller.OvsdbNodeId;
import org.onosproject.ovsdb.controller.OvsdbPort;
import org.onosproject.ovsdb.controller.OvsdbTunnel;
import org.onosproject.ovsdb.rfc.message.OperationResult;
import org.onosproject.ovsdb.rfc.message.TableUpdates;
import org.onosproject.ovsdb.rfc.notation.Row;
import org.onosproject.ovsdb.rfc.notation.UUID;
import org.onosproject.ovsdb.rfc.operations.Operation;
import org.onosproject.ovsdb.rfc.schema.DatabaseSchema;
import java.util.List;
import java.util.Set;
/**
* Test Adapter for OvsdbClientService.
*/
public class OvsdbClientServiceAdapter implements OvsdbClientService {
@Override
public OvsdbNodeId nodeId() {
return null;
}
@Override
public void createTunnel(IpAddress srcIp, IpAddress dstIp) {
}
@Override
public void dropTunnel(IpAddress srcIp, IpAddress dstIp) {
}
@Override
public Set<OvsdbTunnel> getTunnels() {
return null;
}
@Override
public void createBridge(String bridgeName) {
}
@Override
public void dropBridge(String bridgeName) {
}
@Override
public Set<OvsdbBridge> getBridges() {
return null;
}
@Override
public Set<ControllerInfo> getControllers(DeviceId openflowDeviceId) {
return null;
}
@Override
public void setControllersWithUUID(UUID bridgeUuid, List<ControllerInfo> controllers) {
}
@Override
public void setControllersWithDeviceId(DeviceId deviceId, List<ControllerInfo> controllers) {
}
@Override
public void createPort(String bridgeName, String portName) {
}
@Override
public void dropPort(String bridgeName, String portName) {
}
@Override
public Set<OvsdbPort> getPorts() {
return null;
}
@Override
public boolean isConnected() {
return false;
}
@Override
public String getBridgeUuid(String bridgeName) {
return null;
}
@Override
public String getPortUuid(String portName, String bridgeUuid) {
return null;
}
@Override
public String getInterfaceUuid(String portUuid, String portName) {
return null;
}
@Override
public String getControllerUuid(String controllerName, String controllerTarget) {
return null;
}
@Override
public String getOvsUuid(String dbName) {
return null;
}
@Override
public ListenableFuture<DatabaseSchema> getOvsdbSchema(String dbName) {
return null;
}
@Override
public ListenableFuture<TableUpdates> monitorTables(String dbName, String id) {
return null;
}
@Override
public ListenableFuture<List<OperationResult>> transactConfig(String dbName, List<Operation> operations) {
return null;
}
@Override
public DatabaseSchema getDatabaseSchema(String dbName) {
return null;
}
@Override
public Row getRow(String dbName, String tableName, String uuid) {
return null;
}
@Override
public void removeRow(String dbName, String tableName, String uuid) {
}
@Override
public void updateOvsdbStore(String dbName, String tableName, String uuid, Row row) {
}
@Override
public Set<OvsdbPort> getLocalPorts(Iterable<String> ifaceids) {
return null;
}
@Override
public void disconnect() {
}
@Override
public ListenableFuture<JsonNode> getSchema(List<String> dbnames) {
return null;
}
@Override
public ListenableFuture<List<String>> echo() {
return null;
}
@Override
public ListenableFuture<JsonNode> monitor(DatabaseSchema dbSchema, String monitorId) {
return null;
}
@Override
public ListenableFuture<List<String>> listDbs() {
return null;
}
@Override
public ListenableFuture<List<JsonNode>> transact(DatabaseSchema dbSchema, List<Operation> operations) {
return null;
}
}
/*
* Copyright 2015 Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.ovsdb.controller.driver;
import org.onlab.packet.IpAddress;
import org.onlab.packet.TpPort;
import org.onosproject.ovsdb.controller.OvsdbClientService;
import org.onosproject.ovsdb.controller.OvsdbController;
import org.onosproject.ovsdb.controller.OvsdbEventListener;
import org.onosproject.ovsdb.controller.OvsdbNodeId;
import org.onosproject.ovsdb.controller.OvsdbNodeListener;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
/**
* Test Adapter for OvsdbController.
*/
public class OvsdbControllerAdapter implements OvsdbController {
protected ConcurrentHashMap<OvsdbNodeId, OvsdbClientServiceAdapter> ovsdbClients =
new ConcurrentHashMap<OvsdbNodeId, OvsdbClientServiceAdapter>();
@Override
public void addNodeListener(OvsdbNodeListener listener) {
}
@Override
public void removeNodeListener(OvsdbNodeListener listener) {
}
@Override
public void addOvsdbEventListener(OvsdbEventListener listener) {
}
@Override
public void removeOvsdbEventListener(OvsdbEventListener listener) {
}
@Override
public List<OvsdbNodeId> getNodeIds() {
long port = 6653;
return new ArrayList<OvsdbNodeId>(Arrays.asList(
new OvsdbNodeId(IpAddress.valueOf("127.0.0.1"), port)));
}
@Override
public OvsdbClientService getOvsdbClient(OvsdbNodeId nodeId) {
return ovsdbClients.get(nodeId);
}
@Override
public void connect(IpAddress ip, TpPort port) {
}
}
......@@ -15,18 +15,8 @@
*/
package org.onosproject.ovsdb.controller.impl;
import static com.google.common.base.Preconditions.checkNotNull;
import java.math.BigInteger;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArraySet;
import java.util.concurrent.ExecutionException;
import com.fasterxml.jackson.databind.JsonNode;
import com.google.common.collect.ImmutableList;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Deactivate;
......@@ -68,7 +58,17 @@ import org.osgi.service.component.ComponentContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.fasterxml.jackson.databind.JsonNode;
import java.math.BigInteger;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArraySet;
import java.util.concurrent.ExecutionException;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* The implementation of OvsdbController.
......@@ -134,8 +134,7 @@ public class OvsdbControllerImpl implements OvsdbController {
@Override
public List<OvsdbNodeId> getNodeIds() {
// TODO Auto-generated method stub
return null;
return ImmutableList.copyOf(ovsdbClients.keySet());
}
@Override
......@@ -210,8 +209,8 @@ public class OvsdbControllerImpl implements OvsdbController {
* Processes table updates.
*
* @param clientService OvsdbClientService instance
* @param updates TableUpdates instance
* @param dbName ovsdb database name
* @param updates TableUpdates instance
* @param dbName ovsdb database name
*/
private void processTableUpdates(OvsdbClientService clientService,
TableUpdates updates, String dbName)
......@@ -242,8 +241,8 @@ public class OvsdbControllerImpl implements OvsdbController {
Row row = clientService.getRow(OvsdbConstant.DATABASENAME, tableName, uuid.value());
dispatchInterfaceEvent(clientService,
row,
OvsdbEvent.Type.PORT_REMOVED,
dbSchema);
OvsdbEvent.Type.PORT_REMOVED,
dbSchema);
}
clientService.removeRow(dbName, tableName, uuid.value());
}
......@@ -255,10 +254,10 @@ public class OvsdbControllerImpl implements OvsdbController {
* Dispatches event to the north.
*
* @param clientService OvsdbClientService instance
* @param newRow a new row
* @param oldRow an old row
* @param eventType type of event
* @param dbSchema ovsdb database schema
* @param newRow a new row
* @param oldRow an old row
* @param eventType type of event
* @param dbSchema ovsdb database schema
*/
private void dispatchInterfaceEvent(OvsdbClientService clientService,
Row row,
......@@ -283,13 +282,13 @@ public class OvsdbControllerImpl implements OvsdbController {
}
EventSubject eventSubject = new DefaultEventSubject(MacAddress.valueOf(
macAndIfaceId[0]),
macAndIfaceId[0]),
new HashSet<IpAddress>(),
new OvsdbPortName(intf
.getName()),
.getName()),
new OvsdbPortNumber(localPort),
new OvsdbDatapathId(Long
.toString(dpid)),
.toString(dpid)),
new OvsdbPortType(portType),
new OvsdbIfaceId(macAndIfaceId[1]));
for (OvsdbEventListener listener : ovsdbEventListener) {
......@@ -315,7 +314,7 @@ public class OvsdbControllerImpl implements OvsdbController {
String attachedMac = externalIds.get(OvsdbConstant.EXTERNAL_ID_VM_MAC);
if (attachedMac == null) {
log.warn("The attachedMac is null");
log.debug("The attachedMac is null"); //FIXME why always null?
return null;
}
String ifaceid = externalIds
......@@ -324,7 +323,7 @@ public class OvsdbControllerImpl implements OvsdbController {
log.warn("The ifaceid is null");
return null;
}
return new String[] {attachedMac, ifaceid};
return new String[]{attachedMac, ifaceid};
}
/**
......@@ -349,7 +348,7 @@ public class OvsdbControllerImpl implements OvsdbController {
* Gets datapathid from table bridge.
*
* @param clientService OvsdbClientService instance
* @param dbSchema ovsdb database schema
* @param dbSchema ovsdb database schema
* @return datapathid the bridge datapathid
*/
private long getDataPathid(OvsdbClientService clientService,
......
......@@ -15,20 +15,21 @@
*/
package org.onosproject.ovsdb.rfc.notation;
import static com.google.common.base.MoreObjects.toStringHelper;
import static com.google.common.base.Preconditions.checkNotNull;
import com.google.common.collect.Maps;
import java.util.Collection;
import java.util.Map;
import java.util.Objects;
import com.google.common.collect.Maps;
import static com.google.common.base.MoreObjects.toStringHelper;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* Row is the basic element of the OpenVswitch's table.
*/
public final class Row {
private String tableName;
private UUID uuid;
private Map<String, Column> columns;
/**
......@@ -40,9 +41,11 @@ public final class Row {
/**
* Row constructor.
*
* @param tableName table name
*/
public Row(String tableName) {
@Deprecated
private Row(String tableName) {
checkNotNull(tableName, "tableName cannot be null");
this.tableName = tableName;
this.columns = Maps.newHashMap();
......@@ -50,18 +53,22 @@ public final class Row {
/**
* Row constructor.
*
* @param tableName table name
* @param columns Map of Column entity
* @param columns Map of Column entity
*/
public Row(String tableName, Map<String, Column> columns) {
public Row(String tableName, UUID uuid, Map<String, Column> columns) {
checkNotNull(tableName, "table name cannot be null");
checkNotNull(uuid, "uuid cannot be null");
checkNotNull(columns, "columns cannot be null");
this.tableName = tableName;
this.uuid = uuid;
this.columns = columns;
}
/**
* Returns tableName.
*
* @return tableName
*/
public String tableName() {
......@@ -70,6 +77,7 @@ public final class Row {
/**
* Set tableName value.
*
* @param tableName table name
*/
public void setTableName(String tableName) {
......@@ -77,7 +85,26 @@ public final class Row {
}
/**
* Returns uuid.
*
* @return uuid
*/
public UUID uuid() {
return uuid;
}
/**
* Sets uuid value.
*
* @param uuid new uuid
*/
public void setUuid(UUID uuid) {
this.uuid = uuid;
}
/**
* Returns Column by ColumnSchema.
*
* @param columnName column name
* @return Column
*/
......@@ -87,6 +114,7 @@ public final class Row {
/**
* Returns Collection of Column.
*
* @return Collection of Column
*/
public Collection<Column> getColumns() {
......@@ -95,8 +123,9 @@ public final class Row {
/**
* add Column.
*
* @param columnName column name
* @param data Column entity
* @param data Column entity
*/
public void addColumn(String columnName, Column data) {
this.columns.put(columnName, data);
......
......@@ -15,16 +15,17 @@
*/
package org.onosproject.ovsdb.rfc.table;
import java.util.Map;
import java.util.Set;
import org.onosproject.ovsdb.rfc.notation.Column;
import org.onosproject.ovsdb.rfc.notation.OvsdbSet;
import org.onosproject.ovsdb.rfc.notation.Row;
import org.onosproject.ovsdb.rfc.notation.UUID;
import org.onosproject.ovsdb.rfc.schema.DatabaseSchema;
import org.onosproject.ovsdb.rfc.tableservice.AbstractOvsdbTableService;
import org.onosproject.ovsdb.rfc.tableservice.ColumnDescription;
import java.util.Map;
import java.util.Set;
/**
* This class provides operations of Bridge Table.
*/
......@@ -351,7 +352,7 @@ public class Bridge extends AbstractOvsdbTableService {
* of attributes.
* @param controller the column data which column name is "controller"
*/
public void setController(Set<UUID> controller) {
public void setController(OvsdbSet controller) {
ColumnDescription columndesc = new ColumnDescription(
BridgeColumn.CONTROLLER
.columnName(),
......
......@@ -37,6 +37,7 @@ public final class TableGenerator {
* @param tableName table name
* @return Object table entity
*/
//FIXME change the name, it creates a row object, such as a controller.
public static Object createTable(DatabaseSchema dbSchema,
OvsdbTable tableName) {
Row row = new Row();
......
......@@ -15,12 +15,11 @@
*/
package org.onosproject.ovsdb.rfc.utils;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import org.onosproject.ovsdb.rfc.exception.AbnormalJsonNodeException;
import org.onosproject.ovsdb.rfc.exception.UnsupportedException;
import org.onosproject.ovsdb.rfc.jsonrpc.Callback;
......@@ -41,11 +40,11 @@ import org.onosproject.ovsdb.rfc.schema.type.ColumnTypeFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
/**
* JsonNode utility class. convert JsonNode into Object.
......@@ -247,7 +246,7 @@ public final class FromJsonUtil {
validateJsonNode(rowsNode, "rows");
ArrayList<Row> rows = Lists.newArrayList();
for (JsonNode rowNode : rowsNode.get("rows")) {
rows.add(createRow(tableSchema, rowNode));
rows.add(createRow(tableSchema, null, rowNode)); //FIXME null will throw exception
}
return rows;
}
......@@ -285,8 +284,8 @@ public final class FromJsonUtil {
UUID uuid = UUID.uuid(uuidStr);
JsonNode newR = oldNewRow.getValue().get("new");
JsonNode oldR = oldNewRow.getValue().get("old");
Row newRow = newR != null ? createRow(tableSchema, newR) : null;
Row oldRow = oldR != null ? createRow(tableSchema, oldR) : null;
Row newRow = newR != null ? createRow(tableSchema, uuid, newR) : null;
Row oldRow = oldR != null ? createRow(tableSchema, uuid, oldR) : null;
RowUpdate rowUpdate = new RowUpdate(uuid, oldRow, newRow);
rows.put(uuid, rowUpdate);
}
......@@ -299,7 +298,7 @@ public final class FromJsonUtil {
* @param rowNode JsonNode
* @return Row
*/
private static Row createRow(TableSchema tableSchema, JsonNode rowNode) {
private static Row createRow(TableSchema tableSchema, UUID uuid, JsonNode rowNode) {
if (tableSchema == null) {
return null;
}
......@@ -314,7 +313,7 @@ public final class FromJsonUtil {
columns.put(columnName, new Column(columnName, obj));
}
}
return new Row(tableSchema.name(), columns);
return new Row(tableSchema.name(), uuid, columns);
}
}
......
......@@ -8,4 +8,4 @@ export OCN="10.128.12.4"
export OCT=$OC1
export ONOS_USE_SSH=true
export ONOS_APPS=drivers,openflow,proxyarp,mobility
export ONOS_APPS=drivers,openflow,proxyarp,ovsdb
......