andrea
Committed by Gerrit Code Review

Inserted set and get controllers methods in ovsdb controller config

Change-Id: I791ff2ae159d0ac50beff22abda2b187913428f6
1 +/*
2 + * Copyright 2015 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.cli.net;
17 +
18 +import org.apache.karaf.shell.commands.Argument;
19 +import org.apache.karaf.shell.commands.Command;
20 +import org.onosproject.cli.AbstractShellCommand;
21 +import org.onosproject.net.DeviceId;
22 +import org.onosproject.net.behaviour.ControllerConfig;
23 +import org.onosproject.net.driver.DriverHandler;
24 +import org.onosproject.net.driver.DriverService;
25 +
26 +/**
27 + * Sets role of the controller node for the given infrastructure device.
28 + */
29 +@Command(scope = "onos", name = "device-controllers",
30 + description = "gets the list of controllers for the given infrastructure device")
31 +public class DeviceControllersCommand extends AbstractShellCommand {
32 +
33 + @Argument(index = 0, name = "uri", description = "Device ID",
34 + required = true, multiValued = false)
35 + String uri = null;
36 + private DeviceId deviceId;
37 +
38 + @Override
39 + protected void execute() {
40 + DriverService service = get(DriverService.class);
41 + deviceId = DeviceId.deviceId(uri);
42 + DriverHandler h = service.createHandler(deviceId);
43 + ControllerConfig config = h.behaviour(ControllerConfig.class);
44 + config.getControllers().forEach(c -> print(c.target()));
45 + }
46 +
47 +}
1 +/*
2 + * Copyright 2015 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +
17 +package org.onosproject.cli.net;
18 +
19 +import org.apache.karaf.shell.commands.Argument;
20 +import org.apache.karaf.shell.commands.Command;
21 +import org.onosproject.cli.AbstractShellCommand;
22 +import org.onosproject.net.DeviceId;
23 +import org.onosproject.net.behaviour.ControllerConfig;
24 +import org.onosproject.net.behaviour.ControllerInfo;
25 +import org.onosproject.net.driver.DriverHandler;
26 +import org.onosproject.net.driver.DriverService;
27 +
28 +import java.util.ArrayList;
29 +import java.util.Arrays;
30 +import java.util.List;
31 +
32 +/**
33 + * Sets role of the controller node for the given infrastructure device.
34 + */
35 +@Command(scope = "onos", name = "device-setcontrollers",
36 + description = "sets the list of controllers for the given infrastructure device")
37 +public class DeviceSetControllersCommand extends AbstractShellCommand {
38 +
39 + @Argument(index = 0, name = "uri", description = "Device ID",
40 + required = true, multiValued = false)
41 + String uri = null;
42 +
43 + @Argument(index = 1, name = "controllersListStrings", description = "list of " +
44 + "controllers to set for the specified device",
45 + required = true, multiValued = true)
46 + String[] controllersListStrings = null;
47 +
48 + private DeviceId deviceId;
49 + private List<ControllerInfo> newControllers = new ArrayList<>();
50 +
51 + @Override
52 + protected void execute() {
53 +
54 + Arrays.asList(controllersListStrings).forEach(
55 + cInfoString -> newControllers.add(new ControllerInfo(cInfoString)));
56 + DriverService service = get(DriverService.class);
57 + deviceId = DeviceId.deviceId(uri);
58 + DriverHandler h = service.createHandler(deviceId);
59 + ControllerConfig config = h.behaviour(ControllerConfig.class);
60 + print("before:");
61 + config.getControllers().forEach(c -> print(c.target()));
62 +
63 + config.setControllers(newControllers);
64 + print("after:");
65 + config.getControllers().forEach(c -> print(c.target()));
66 + print("size %d", config.getControllers().size());
67 + }
68 +
69 +}
...@@ -105,6 +105,18 @@ ...@@ -105,6 +105,18 @@
105 </completers> 105 </completers>
106 </command> 106 </command>
107 <command> 107 <command>
108 + <action class="org.onosproject.cli.net.DeviceControllersCommand"/>
109 + <completers>
110 + <ref component-id="deviceIdCompleter"/>
111 + </completers>
112 + </command>
113 + <command>
114 + <action class="org.onosproject.cli.net.DeviceSetControllersCommand"/>
115 + <completers>
116 + <ref component-id="deviceIdCompleter"/>
117 + </completers>
118 + </command>
119 + <command>
108 <action class="org.onosproject.cli.net.DeviceRemoveCommand"/> 120 <action class="org.onosproject.cli.net.DeviceRemoveCommand"/>
109 <completers> 121 <completers>
110 <ref component-id="deviceIdCompleter"/> 122 <ref component-id="deviceIdCompleter"/>
......
...@@ -15,23 +15,27 @@ ...@@ -15,23 +15,27 @@
15 */ 15 */
16 package org.onosproject.net.behaviour; 16 package org.onosproject.net.behaviour;
17 17
18 +import org.onosproject.net.driver.HandlerBehaviour;
19 +
18 import java.util.List; 20 import java.util.List;
19 21
20 /** 22 /**
21 * Device behaviour to obtain and set controllers at the device. 23 * Device behaviour to obtain and set controllers at the device.
22 */ 24 */
23 -public interface ControllerConfig { 25 +public interface ControllerConfig extends HandlerBehaviour {
24 26
25 //TODO: add other controller parameters as needed. 27 //TODO: add other controller parameters as needed.
26 28
27 /** 29 /**
28 * Obtain the list of controller which are currently configured. 30 * Obtain the list of controller which are currently configured.
31 + *
29 * @return a list for controller descriptions 32 * @return a list for controller descriptions
30 */ 33 */
31 List<ControllerInfo> getControllers(); 34 List<ControllerInfo> getControllers();
32 35
33 /** 36 /**
34 * Set a list of controllers on a device. 37 * Set a list of controllers on a device.
38 + *
35 * @param controllers a list of controller descriptions 39 * @param controllers a list of controller descriptions
36 */ 40 */
37 void setControllers(List<ControllerInfo> controllers); 41 void setControllers(List<ControllerInfo> controllers);
......
...@@ -15,24 +15,112 @@ ...@@ -15,24 +15,112 @@
15 */ 15 */
16 package org.onosproject.net.behaviour; 16 package org.onosproject.net.behaviour;
17 17
18 +import com.google.common.base.Preconditions;
18 import org.onlab.packet.IpAddress; 19 import org.onlab.packet.IpAddress;
19 20
21 +import java.util.Objects;
22 +
20 /** 23 /**
21 * Represents information for a device to connect to a controller. 24 * Represents information for a device to connect to a controller.
22 */ 25 */
23 public class ControllerInfo { 26 public class ControllerInfo {
24 27
25 - public final IpAddress ip; 28 + private IpAddress ip = IpAddress.valueOf("0.0.0.0");
26 - public final int tcpPort; 29 + private int port = 6653;
30 + private String type = "error";
27 31
28 /** 32 /**
29 * Information for contacting the controller. 33 * Information for contacting the controller.
30 * 34 *
31 * @param ip the ip address 35 * @param ip the ip address
32 - * @param tcpPort the tcp port 36 + * @param port the tcp port
33 */ 37 */
34 - public ControllerInfo(IpAddress ip, int tcpPort) { 38 + public ControllerInfo(IpAddress ip, int port, String type) {
35 this.ip = ip; 39 this.ip = ip;
36 - this.tcpPort = tcpPort; 40 + this.port = port;
41 + this.type = type;
42 + }
43 +
44 + /**
45 + * Information for contacting the controller, if some information
46 + * is not contained in the target string because it's optional
47 + * it's leaved as in the field declaration (default values).
48 + *
49 + * @param target column returned from ovsdb query
50 + */
51 + public ControllerInfo(String target) {
52 + String[] data = target.split(":");
53 + this.type = data[0];
54 + Preconditions.checkArgument(!data[0].contains("unix"),
55 + "Unable to create controller info " +
56 + "from {} because it's based " +
57 + "on unix sockets", target);
58 + if (data[0].startsWith("p")) {
59 + if (data.length >= 2) {
60 + this.port = Integer.parseInt(data[1]);
61 + }
62 + if (data.length == 3) {
63 + this.ip = IpAddress.valueOf(data[2]);
64 + }
65 + } else {
66 + this.ip = IpAddress.valueOf(data[1]);
67 + if (data.length == 3) {
68 + this.port = Integer.parseInt(data[2]);
69 + }
70 + }
71 + }
72 +
73 + /**
74 + * Exposes the ip address of the controller.
75 + *
76 + * @return IpAddress ip address
77 + */
78 + public IpAddress ip() {
79 + return ip;
80 + }
81 +
82 + /**
83 + * Exposes the tcp port of the controller.
84 + *
85 + * @return int tcp port
86 + */
87 + public int port() {
88 + return port;
89 + }
90 +
91 + /**
92 + * Exposes the type of the controller connection.
93 + *
94 + * @return String type
95 + */
96 + public String type() {
97 + return type;
98 + }
99 +
100 + public String target() {
101 + if (type.startsWith("p")) {
102 + return type + ":" + port + ":" + ip;
103 + } else {
104 + return type + ":" + ip + ":" + port;
105 + }
106 + }
107 +
108 +
109 + @Override
110 + public int hashCode() {
111 + return Objects.hash(ip, port, type);
112 + }
113 +
114 + @Override
115 + public boolean equals(Object toBeCompared) {
116 + if (toBeCompared instanceof ControllerInfo) {
117 + ControllerInfo controllerInfo = (ControllerInfo) toBeCompared;
118 + if (controllerInfo.type().equals(this.type)
119 + && controllerInfo.ip().equals(this.ip())
120 + && controllerInfo.port() == this.port) {
121 + return true;
122 + }
123 + }
124 + return false;
37 } 125 }
38 } 126 }
......
1 +/*
2 + * Copyright 2015 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +
17 +package org.onosproject.net.behaviour;
18 +
19 +
20 +import org.junit.Rule;
21 +import org.junit.Test;
22 +import org.junit.rules.ExpectedException;
23 +import org.onlab.packet.IpAddress;
24 +
25 +import java.util.ArrayList;
26 +import java.util.Arrays;
27 +import java.util.List;
28 +
29 +import static org.junit.Assert.*;
30 +
31 +/**
32 + * Test for ControllerInfo class.
33 + */
34 +public class ControllerInfoTest {
35 + @Rule
36 + public ExpectedException thrown = ExpectedException.none();
37 +
38 + @Test
39 + public void tcpSslFormat() {
40 + String target = "tcp:192.168.1.1:6653";
41 + ControllerInfo controllerInfo = new ControllerInfo(target);
42 + assertEquals("wrong type", controllerInfo.type(), "tcp");
43 + assertEquals("wrong ip", controllerInfo.ip(), IpAddress.valueOf("192.168.1.1"));
44 + assertEquals("wrong port", controllerInfo.port(), 6653);
45 +
46 + }
47 +
48 + @Test
49 + public void ptcpPsslFormat() {
50 + String target = "ptcp:6653:192.168.1.1";
51 + ControllerInfo controllerInfo = new ControllerInfo(target);
52 + assertEquals("wrong type", controllerInfo.type(), "ptcp");
53 + assertEquals("wrong ip", controllerInfo.ip(), IpAddress.valueOf("192.168.1.1"));
54 + assertEquals("wrong port", controllerInfo.port(), 6653);
55 +
56 + }
57 +
58 + @Test
59 + public void unixFormat() {
60 + String target = "unix:file";
61 + thrown.expect(IllegalArgumentException.class);
62 + ControllerInfo controllerInfo = new ControllerInfo(target);
63 + assertTrue("wrong type", controllerInfo.type().contains("unix"));
64 + assertNull("wrong ip", controllerInfo.ip());
65 + assertEquals("wrong port", controllerInfo.port(), -1);
66 +
67 + }
68 +
69 + @Test
70 + public void defaultValues() {
71 + String target = "tcp:192.168.1.1";
72 + ControllerInfo controllerInfo = new ControllerInfo(target);
73 + assertEquals("wrong type", controllerInfo.type(), "tcp");
74 + assertEquals("wrong ip", controllerInfo.ip(), IpAddress.valueOf("192.168.1.1"));
75 + assertEquals("wrong port", controllerInfo.port(), 6653);
76 + String target1 = "ptcp:5000:";
77 + ControllerInfo controllerInfo2 = new ControllerInfo(target1);
78 + assertEquals("wrong type", controllerInfo2.type(), "ptcp");
79 + assertEquals("wrong ip", controllerInfo2.ip(), IpAddress.valueOf("0.0.0.0"));
80 + assertEquals("wrong port", controllerInfo2.port(), 5000);
81 + String target2 = "ptcp:";
82 + ControllerInfo controllerInfo3 = new ControllerInfo(target2);
83 + assertEquals("wrong type", controllerInfo3.type(), "ptcp");
84 + assertEquals("wrong ip", controllerInfo3.ip(), IpAddress.valueOf("0.0.0.0"));
85 + assertEquals("wrong port", controllerInfo3.port(), 6653);
86 + }
87 +
88 +
89 + @Test
90 + public void testEquals() {
91 + String target1 = "ptcp:6653:192.168.1.1";
92 + ControllerInfo controllerInfo1 = new ControllerInfo(target1);
93 + String target2 = "ptcp:6653:192.168.1.1";
94 + ControllerInfo controllerInfo2 = new ControllerInfo(target2);
95 + assertTrue("wrong equals method", controllerInfo1.equals(controllerInfo2));
96 + }
97 +
98 + @Test
99 + public void testListEquals() {
100 + String target1 = "ptcp:6653:192.168.1.1";
101 + ControllerInfo controllerInfo1 = new ControllerInfo(target1);
102 + String target2 = "ptcp:6653:192.168.1.1";
103 + ControllerInfo controllerInfo2 = new ControllerInfo(target2);
104 + String target3 = "tcp:192.168.1.1:6653";
105 + ControllerInfo controllerInfo3 = new ControllerInfo(target3);
106 + String target4 = "tcp:192.168.1.1:6653";
107 + ControllerInfo controllerInfo4 = new ControllerInfo(target4);
108 + List<ControllerInfo> list1 = new ArrayList<>(Arrays.asList(controllerInfo1, controllerInfo3));
109 + List<ControllerInfo> list2 = new ArrayList<>(Arrays.asList(controllerInfo2, controllerInfo4));
110 + assertTrue("wrong equals list method", list1.equals(list2));
111 + }
112 +}
...@@ -55,7 +55,7 @@ ...@@ -55,7 +55,7 @@
55 <dependency> 55 <dependency>
56 <groupId>org.onosproject</groupId> 56 <groupId>org.onosproject</groupId>
57 <artifactId>onos-core-serializers</artifactId> 57 <artifactId>onos-core-serializers</artifactId>
58 - <version>1.4.0-SNAPSHOT</version> 58 + <version>${project.version}</version>
59 </dependency> 59 </dependency>
60 <dependency> 60 <dependency>
61 <groupId>org.onosproject</groupId> 61 <groupId>org.onosproject</groupId>
...@@ -72,6 +72,25 @@ ...@@ -72,6 +72,25 @@
72 <groupId>org.apache.felix</groupId> 72 <groupId>org.apache.felix</groupId>
73 <artifactId>org.apache.felix.scr.annotations</artifactId> 73 <artifactId>org.apache.felix.scr.annotations</artifactId>
74 </dependency> 74 </dependency>
75 + <dependency>
76 + <groupId>org.onosproject</groupId>
77 + <artifactId>onos-api</artifactId>
78 + <version>${project.version}</version>
79 + <classifier>tests</classifier>
80 + <scope>test</scope>
81 + </dependency>
82 + <dependency>
83 + <groupId>org.onosproject</groupId>
84 + <artifactId>onlab-junit</artifactId>
85 + <scope>test</scope>
86 + </dependency>
87 + <dependency>
88 + <groupId>org.onosproject</groupId>
89 + <artifactId>onos-ovsdb-api</artifactId>
90 + <version>${project.version}</version>
91 + <classifier>tests</classifier>
92 + <scope>test</scope>
93 + </dependency>
75 </dependencies> 94 </dependencies>
76 95
77 <build> 96 <build>
......
1 +/*
2 + * Copyright 2015 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +
17 +package org.onosproject.driver.ovsdb;
18 +
19 +import org.onlab.packet.IpAddress;
20 +import org.onlab.packet.TpPort;
21 +import org.onosproject.net.AnnotationKeys;
22 +import org.onosproject.net.DeviceId;
23 +import org.onosproject.net.behaviour.ControllerConfig;
24 +import org.onosproject.net.behaviour.ControllerInfo;
25 +import org.onosproject.net.device.DeviceService;
26 +import org.onosproject.net.driver.AbstractHandlerBehaviour;
27 +import org.onosproject.net.driver.DriverHandler;
28 +import org.onosproject.ovsdb.controller.OvsdbBridge;
29 +import org.onosproject.ovsdb.controller.OvsdbClientService;
30 +import org.onosproject.ovsdb.controller.OvsdbController;
31 +import org.onosproject.ovsdb.controller.OvsdbNodeId;
32 +
33 +import java.util.ArrayList;
34 +import java.util.List;
35 +import java.util.Set;
36 +import java.util.stream.Collectors;
37 +
38 +import static com.google.common.base.Preconditions.checkState;
39 +import static org.onlab.util.Tools.delay;
40 +
41 +/**
42 + * Implementation of controller config which allows to get and set controllers.
43 + */
44 +public class OvsdbControllerConfig extends AbstractHandlerBehaviour implements ControllerConfig {
45 + @Override
46 + public List<ControllerInfo> getControllers() {
47 + DriverHandler handler = handler();
48 + OvsdbClientService clientService = getOvsdbClientService(handler);
49 + Set<ControllerInfo> controllers = clientService.getControllers(
50 + handler().data().deviceId());
51 + return new ArrayList<>(controllers);
52 + }
53 +
54 + @Override
55 + public void setControllers(List<ControllerInfo> controllers) {
56 + DriverHandler handler = handler();
57 + OvsdbClientService clientService = getOvsdbClientService(handler);
58 + if (!clientService.getControllers(handler().data().deviceId())
59 + .equals(controllers)) {
60 + clientService.setControllersWithDeviceId(handler().
61 + data().deviceId(), controllers);
62 + }
63 + }
64 +
65 + // Used for getting OvsdbClientService.
66 + private OvsdbClientService getOvsdbClientService(DriverHandler handler) {
67 + OvsdbController ovsController = handler.get(OvsdbController.class);
68 + DeviceService deviceService = handler.get(DeviceService.class);
69 + DeviceId ofDeviceId = handler.data().deviceId();
70 + String[] mgmtAddress = deviceService.getDevice(ofDeviceId)
71 + .annotations().value(AnnotationKeys.MANAGEMENT_ADDRESS).split(":");
72 + String targetIp = mgmtAddress[0];
73 + TpPort targetPort = null;
74 + if (mgmtAddress.length > 1) {
75 + targetPort = TpPort.tpPort(Integer.parseInt(mgmtAddress[1]));
76 + }
77 +
78 + List<OvsdbNodeId> nodeIds = ovsController.getNodeIds().stream()
79 + .filter(nodeId -> nodeId.getIpAddress().equals(targetIp))
80 + .collect(Collectors.toList());
81 + if (nodeIds.size() == 0) {
82 + //TODO decide what port?
83 + ovsController.connect(IpAddress.valueOf(targetIp),
84 + targetPort == null ? TpPort.tpPort(6640) : targetPort);
85 + delay(1000); //FIXME... connect is async
86 + }
87 + List<OvsdbClientService> clientServices = ovsController.getNodeIds().stream()
88 + .filter(nodeId -> nodeId.getIpAddress().equals(targetIp))
89 + .map(ovsController::getOvsdbClient)
90 + .filter(cs -> cs.getBridges().stream().anyMatch(b -> dpidMatches(b, ofDeviceId)))
91 + .collect(Collectors.toList());
92 + checkState(clientServices.size() > 0, "No clientServices found");
93 + //FIXME add connection to management address if null --> done ?
94 + return clientServices.size() > 0 ? clientServices.get(0) : null;
95 + }
96 +
97 + private static boolean dpidMatches(OvsdbBridge bridge, DeviceId deviceId) {
98 + String bridgeDpid = "of:" + bridge.datapathId().value();
99 + String ofDpid = deviceId.toString();
100 + return bridgeDpid.equals(ofDpid);
101 + }
102 +}
...\ No newline at end of file ...\ No newline at end of file
...@@ -30,6 +30,8 @@ ...@@ -30,6 +30,8 @@
30 manufacturer="Nicira, Inc\." hwVersion="Open vSwitch" swVersion="2\..*"> 30 manufacturer="Nicira, Inc\." hwVersion="Open vSwitch" swVersion="2\..*">
31 <behaviour api="org.onosproject.openflow.controller.driver.OpenFlowSwitchDriver" 31 <behaviour api="org.onosproject.openflow.controller.driver.OpenFlowSwitchDriver"
32 impl="org.onosproject.driver.handshaker.NiciraSwitchHandshaker"/> 32 impl="org.onosproject.driver.handshaker.NiciraSwitchHandshaker"/>
33 + <behaviour api="org.onosproject.net.behaviour.ControllerConfig"
34 + impl="org.onosproject.driver.ovsdb.OvsdbControllerConfig"/>
33 </driver> 35 </driver>
34 <driver name="ovs-corsa" extends="ovs" 36 <driver name="ovs-corsa" extends="ovs"
35 manufacturer="Corsa" hwVersion="emulation" swVersion="0.0.0"> 37 manufacturer="Corsa" hwVersion="emulation" swVersion="0.0.0">
......
1 +/*
2 + * Copyright 2015 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +
17 +package org.onosproject.driver.ovsdb;
18 +
19 +import com.google.common.collect.ImmutableMap;
20 +import org.junit.Before;
21 +import org.junit.Test;
22 +import org.onosproject.net.DeviceId;
23 +import org.onosproject.net.behaviour.ControllerConfig;
24 +import org.onosproject.net.device.DeviceServiceAdapter;
25 +import org.onosproject.net.driver.DefaultDriver;
26 +import org.onosproject.net.driver.DefaultDriverData;
27 +import org.onosproject.net.driver.DefaultDriverHandler;
28 +import org.onosproject.ovsdb.controller.driver.OvsdbClientServiceAdapter;
29 +import org.onosproject.ovsdb.controller.driver.OvsdbControllerAdapter;
30 +
31 +/**
32 + * Created by Andrea on 10/7/15.
33 + */
34 +public class OvsdbControllerConfigTest {
35 +
36 +
37 + private static final DeviceId DEVICE_ID = DeviceId.deviceId("foo");
38 +
39 + private DefaultDriver ddc;
40 + private DefaultDriverData data;
41 + private DefaultDriverHandler handler;
42 +
43 + private TestDeviceService deviceService = new TestDeviceService();
44 + private TestOvsdbController controller = new TestOvsdbController();
45 + private TestOvsdbClient client = new TestOvsdbClient();
46 +
47 + private OvsdbControllerConfig controllerConfig;
48 +
49 +
50 + @Before
51 + public void setUp() {
52 + controllerConfig = new OvsdbControllerConfig();
53 +
54 + ddc = new DefaultDriver("foo.bar", null, "Circus", "lux", "1.2a",
55 + ImmutableMap.of(ControllerConfig.class,
56 + OvsdbControllerConfig.class),
57 + ImmutableMap.of("foo", "bar"));
58 + data = new DefaultDriverData(ddc, DEVICE_ID);
59 + handler = new DefaultDriverHandler(data);
60 + //handler.controllerConfig.setHandler(handler);
61 + //TODO setTestService directory on handler
62 + //TODO setup ovsdb fake controller with fake ovsdbclient
63 + //TODO setup fake device service
64 + }
65 +
66 + @Test
67 + public void testGetControllers() throws Exception {
68 +// DriverService driverService = new Driv
69 +// AbstractBehaviour ab = new AbstractBehaviour();
70 +// DriverHandler handler = handler();
71 +// List<ControllerInfo> controllersList =
72 +// controllerConfig.getControllers(DeviceId.deviceId("0000000000000018"));
73 +// log.info("controllers " + controllersList);
74 +
75 + }
76 +
77 + @Test
78 + public void testSetControllers() throws Exception {
79 +
80 + }
81 +
82 +
83 + private class TestDeviceService extends DeviceServiceAdapter {
84 +
85 + }
86 +
87 + private class TestOvsdbController extends OvsdbControllerAdapter {
88 +
89 +
90 + }
91 +
92 + private class TestOvsdbClient extends OvsdbClientServiceAdapter {
93 +
94 + }
95 +}
...\ No newline at end of file ...\ No newline at end of file
...@@ -48,6 +48,10 @@ ...@@ -48,6 +48,10 @@
48 </dependency> 48 </dependency>
49 <dependency> 49 <dependency>
50 <groupId>org.onosproject</groupId> 50 <groupId>org.onosproject</groupId>
51 + <artifactId>onos-api</artifactId>
52 + </dependency>
53 + <dependency>
54 + <groupId>org.onosproject</groupId>
51 <artifactId>onos-ovsdb-rfc</artifactId> 55 <artifactId>onos-ovsdb-rfc</artifactId>
52 <version>${project.version}</version> 56 <version>${project.version}</version>
53 </dependency> 57 </dependency>
......
...@@ -15,19 +15,20 @@ ...@@ -15,19 +15,20 @@
15 */ 15 */
16 package org.onosproject.ovsdb.controller; 16 package org.onosproject.ovsdb.controller;
17 17
18 -import java.util.List; 18 +import com.google.common.util.concurrent.ListenableFuture;
19 -import java.util.Set;
20 -
21 import org.onlab.packet.IpAddress; 19 import org.onlab.packet.IpAddress;
22 - 20 +import org.onosproject.net.DeviceId;
21 +import org.onosproject.net.behaviour.ControllerInfo;
23 import org.onosproject.ovsdb.rfc.jsonrpc.OvsdbRPC; 22 import org.onosproject.ovsdb.rfc.jsonrpc.OvsdbRPC;
24 import org.onosproject.ovsdb.rfc.message.OperationResult; 23 import org.onosproject.ovsdb.rfc.message.OperationResult;
25 import org.onosproject.ovsdb.rfc.message.TableUpdates; 24 import org.onosproject.ovsdb.rfc.message.TableUpdates;
26 import org.onosproject.ovsdb.rfc.notation.Row; 25 import org.onosproject.ovsdb.rfc.notation.Row;
26 +import org.onosproject.ovsdb.rfc.notation.UUID;
27 import org.onosproject.ovsdb.rfc.operations.Operation; 27 import org.onosproject.ovsdb.rfc.operations.Operation;
28 import org.onosproject.ovsdb.rfc.schema.DatabaseSchema; 28 import org.onosproject.ovsdb.rfc.schema.DatabaseSchema;
29 29
30 -import com.google.common.util.concurrent.ListenableFuture; 30 +import java.util.List;
31 +import java.util.Set;
31 32
32 /** 33 /**
33 * Represents to provider facing side of a node. 34 * Represents to provider facing side of a node.
...@@ -85,6 +86,29 @@ public interface OvsdbClientService extends OvsdbRPC { ...@@ -85,6 +86,29 @@ public interface OvsdbClientService extends OvsdbRPC {
85 Set<OvsdbBridge> getBridges(); 86 Set<OvsdbBridge> getBridges();
86 87
87 /** 88 /**
89 + * Gets controllers of the node.
90 + *
91 + * @return set of controllers; empty if no controller is find
92 + */
93 + Set<ControllerInfo> getControllers(DeviceId openflowDeviceId);
94 +
95 + /**
96 + * sets the controllers of the node to the ones passed in the list.
97 + *
98 + * @param bridgeUuid UUid for the bridge we are settings the controls on
99 + * @param controllers of controllers; empty if no controller is find
100 + */
101 + void setControllersWithUUID(UUID bridgeUuid, List<ControllerInfo> controllers);
102 +
103 + /**
104 + * sets the controllers of the node to the ones passed in the list.
105 + *
106 + * @param deviceId deviceId for the bridge we are settings the controls on
107 + * @param controllers of controllers; empty if no controller is find
108 + */
109 + void setControllersWithDeviceId(DeviceId deviceId, List<ControllerInfo> controllers);
110 +
111 + /**
88 * Creates a port. 112 * Creates a port.
89 * 113 *
90 * @param bridgeName bridge name 114 * @param bridgeName bridge name
......
...@@ -15,19 +15,18 @@ ...@@ -15,19 +15,18 @@
15 */ 15 */
16 package org.onosproject.ovsdb.controller.driver; 16 package org.onosproject.ovsdb.controller.driver;
17 17
18 +import com.fasterxml.jackson.databind.JsonNode;
19 +import com.google.common.base.Function;
20 +import com.google.common.collect.Lists;
21 +import com.google.common.collect.Maps;
22 +import com.google.common.collect.Sets;
23 +import com.google.common.util.concurrent.Futures;
24 +import com.google.common.util.concurrent.ListenableFuture;
25 +import com.google.common.util.concurrent.SettableFuture;
18 import io.netty.channel.Channel; 26 import io.netty.channel.Channel;
19 -
20 -import java.net.InetSocketAddress;
21 -import java.util.ArrayList;
22 -import java.util.HashSet;
23 -import java.util.Iterator;
24 -import java.util.List;
25 -import java.util.Map;
26 -import java.util.Set;
27 -import java.util.concurrent.ConcurrentMap;
28 -import java.util.concurrent.ExecutionException;
29 -
30 import org.onlab.packet.IpAddress; 27 import org.onlab.packet.IpAddress;
28 +import org.onosproject.net.DeviceId;
29 +import org.onosproject.net.behaviour.ControllerInfo;
31 import org.onosproject.ovsdb.controller.OvsdbBridge; 30 import org.onosproject.ovsdb.controller.OvsdbBridge;
32 import org.onosproject.ovsdb.controller.OvsdbBridgeName; 31 import org.onosproject.ovsdb.controller.OvsdbBridgeName;
33 import org.onosproject.ovsdb.controller.OvsdbClientService; 32 import org.onosproject.ovsdb.controller.OvsdbClientService;
...@@ -71,14 +70,17 @@ import org.onosproject.ovsdb.rfc.utils.MutationUtil; ...@@ -71,14 +70,17 @@ import org.onosproject.ovsdb.rfc.utils.MutationUtil;
71 import org.slf4j.Logger; 70 import org.slf4j.Logger;
72 import org.slf4j.LoggerFactory; 71 import org.slf4j.LoggerFactory;
73 72
74 -import com.fasterxml.jackson.databind.JsonNode; 73 +import java.net.InetSocketAddress;
75 -import com.google.common.base.Function; 74 +import java.util.ArrayList;
76 -import com.google.common.collect.Lists; 75 +import java.util.HashSet;
77 -import com.google.common.collect.Maps; 76 +import java.util.Iterator;
78 -import com.google.common.collect.Sets; 77 +import java.util.List;
79 -import com.google.common.util.concurrent.Futures; 78 +import java.util.Map;
80 -import com.google.common.util.concurrent.ListenableFuture; 79 +import java.util.Set;
81 -import com.google.common.util.concurrent.SettableFuture; 80 +import java.util.concurrent.ConcurrentMap;
81 +import java.util.concurrent.ExecutionException;
82 +import java.util.concurrent.atomic.AtomicReference;
83 +import java.util.stream.Collectors;
82 84
83 /** 85 /**
84 * An representation of an ovsdb client. 86 * An representation of an ovsdb client.
...@@ -170,7 +172,6 @@ public class DefaultOvsdbClient ...@@ -170,7 +172,6 @@ public class DefaultOvsdbClient
170 * 172 *
171 * @param dbName the ovsdb database name 173 * @param dbName the ovsdb database name
172 * @param tableName the ovsdb table name 174 * @param tableName the ovsdb table name
173 - *
174 * @return ovsRowStore, empty if row store is find 175 * @return ovsRowStore, empty if row store is find
175 */ 176 */
176 private OvsdbRowStore getRowStore(String dbName, String tableName) { 177 private OvsdbRowStore getRowStore(String dbName, String tableName) {
...@@ -475,7 +476,7 @@ public class DefaultOvsdbClient ...@@ -475,7 +476,7 @@ public class DefaultOvsdbClient
475 updateConfig(OvsdbConstant.BRIDGE, "_uuid", bridgeUuid, bridge.getRow()); 476 updateConfig(OvsdbConstant.BRIDGE, "_uuid", bridgeUuid, bridge.getRow());
476 } 477 }
477 478
478 - setController(bridgeUuid); 479 + setControllerAuto(bridgeUuid);
479 log.info("Create bridge success"); 480 log.info("Create bridge success");
480 } 481 }
481 482
...@@ -484,7 +485,7 @@ public class DefaultOvsdbClient ...@@ -484,7 +485,7 @@ public class DefaultOvsdbClient
484 * 485 *
485 * @param bridgeUuid bridge uuid 486 * @param bridgeUuid bridge uuid
486 */ 487 */
487 - private void setController(String bridgeUuid) { 488 + private void setControllerAuto(String bridgeUuid) {
488 String controllerUuid = null; 489 String controllerUuid = null;
489 String iPAddress = IpAddress.valueOf(((InetSocketAddress) channel 490 String iPAddress = IpAddress.valueOf(((InetSocketAddress) channel
490 .localAddress()) 491 .localAddress())
...@@ -495,13 +496,113 @@ public class DefaultOvsdbClient ...@@ -495,13 +496,113 @@ public class DefaultOvsdbClient
495 String target = "tcp:" + iPAddress + ":" + OvsdbConstant.OFPORT; 496 String target = "tcp:" + iPAddress + ":" + OvsdbConstant.OFPORT;
496 log.debug("controller IP {}: port {}", iPAddress, OvsdbConstant.OFPORT); 497 log.debug("controller IP {}: port {}", iPAddress, OvsdbConstant.OFPORT);
497 498
499 + setController(bridgeUuid, target);
500 +
501 + }
502 +
503 + /**
504 + * Sets the Controllers.
505 + *
506 + * @param bridgeUuid bridge uuid
507 + */
508 + @Override
509 + public void setControllersWithUUID(UUID bridgeUuid, List<ControllerInfo> controllers) {
510 +
498 DatabaseSchema dbSchema = schema.get(OvsdbConstant.DATABASENAME); 511 DatabaseSchema dbSchema = schema.get(OvsdbConstant.DATABASENAME);
512 + if (dbSchema == null) {
513 + log.debug("There is no schema");
514 + return;
515 + }
516 + List<Controller> oldControllers = getControllers(bridgeUuid);
517 + if (oldControllers == null) {
518 + log.warn("There are no controllers");
519 + return;
520 + }
521 +
522 + Set<UUID> newControllerUuids = new HashSet<>();
523 +
524 + Set<ControllerInfo> newControllers = new HashSet<>(controllers);
525 + List<Controller> removeControllers = new ArrayList<>();
526 + oldControllers.forEach(controller -> {
527 + ControllerInfo controllerInfo = new ControllerInfo((String) controller.getTargetColumn().data());
528 + if (newControllers.contains(controllerInfo)) {
529 + newControllers.remove(controllerInfo);
530 + newControllerUuids.add(controller.getRow().uuid());
531 + } else {
532 + removeControllers.add(controller);
533 + }
534 + });
535 + OvsdbRowStore controllerRowStore = getRowStore(OvsdbConstant.DATABASENAME,
536 + OvsdbConstant.CONTROLLER);
537 + if (controllerRowStore == null) {
538 + log.debug("There is no controller table");
539 + return;
540 + }
541 +
542 +// removeControllers.forEach(c -> controllerRowStore.deleteRow(c.getRow().uuid().value()));
543 + removeControllers.forEach(c -> deleteConfig(OvsdbConstant.CONTROLLER, "_uuid", c.getRow().uuid().value(),
544 + OvsdbConstant.BRIDGE, "controller"));
545 +
546 + newControllers.stream().map(c -> {
499 Controller controller = (Controller) TableGenerator 547 Controller controller = (Controller) TableGenerator
500 .createTable(dbSchema, OvsdbTable.CONTROLLER); 548 .createTable(dbSchema, OvsdbTable.CONTROLLER);
549 + controller.setTarget(c.target());
550 + return controller;
551 + }).forEach(c -> {
552 +// UUID uuid = c.getRow().uuid();
553 +// controllerRowStore.insertRow(uuid.value(), c.getRow());
554 +// newControllerUuids.add(uuid);
555 +
556 + String uuid = insertConfig(OvsdbConstant.CONTROLLER, "_uuid",
557 + OvsdbConstant.BRIDGE, "controller", bridgeUuid.value(),
558 + c.getRow());
559 + log.warn("insertConfig uuid {}", uuid);
560 + log.warn("row uuid {}", c.getRow().uuid());
561 + //log.warn("rowStore uuid {}", controllerRowStore.getRowStore());
562 + newControllerUuids.add(UUID.uuid(uuid));
563 +
564 + });
565 +
566 + OvsdbRowStore rowStore = getRowStore(OvsdbConstant.DATABASENAME,
567 + OvsdbConstant.BRIDGE);
568 + if (rowStore == null) {
569 + log.debug("There is no bridge table");
570 + return;
571 + }
572 +
573 + Row bridgeRow = rowStore.getRow(bridgeUuid.value());
574 + Bridge bridge = (Bridge) TableGenerator.getTable(dbSchema, bridgeRow, OvsdbTable.BRIDGE);
575 + bridge.setController(OvsdbSet.ovsdbSet(newControllerUuids));
576 + updateConfig(OvsdbConstant.BRIDGE, "_uuid", bridgeUuid.value(), bridge.getRow());
577 +
578 + //rowStore.insertRow(bridgeUuid.value(), bridge.getRow()); //TODO do we need to do this?
579 + }
580 +
581 + /**
582 + * Sets the Controllers.
583 + *
584 + * @param deviceId bridge uuid
585 + */
586 + @Override
587 + public void setControllersWithDeviceId(DeviceId deviceId, List<ControllerInfo> controllers) {
588 + setControllersWithUUID(getBridgeUUID(deviceId), controllers);
589 + }
590 +
591 + private void setController(String bridgeUuid, String target) {
592 + String controllerUuid;
593 + DatabaseSchema dbSchema = schema.get(OvsdbConstant.DATABASENAME);
594 +
595 + // 1. get the bridge row
596 + // 2. delete different controllers and save the same controller.
597 + // 3. add new controllers
598 + // 4. update bridge row
599 +
501 600
502 - if (controller != null) {
503 - controller.setTarget(target);
504 controllerUuid = getControllerUuid(OvsdbConstant.CONTROLLER, target); 601 controllerUuid = getControllerUuid(OvsdbConstant.CONTROLLER, target);
602 +
603 + Controller controller = (Controller) TableGenerator
604 + .createTable(dbSchema, OvsdbTable.CONTROLLER);
605 + if (controller != null) {
505 if (controllerUuid == null) { 606 if (controllerUuid == null) {
506 607
507 insertConfig(OvsdbConstant.CONTROLLER, "_uuid", 608 insertConfig(OvsdbConstant.CONTROLLER, "_uuid",
...@@ -514,12 +615,11 @@ public class DefaultOvsdbClient ...@@ -514,12 +615,11 @@ public class DefaultOvsdbClient
514 .createTable(dbSchema, OvsdbTable.BRIDGE); 615 .createTable(dbSchema, OvsdbTable.BRIDGE);
515 Set<UUID> controllerUuids = new HashSet<>(); 616 Set<UUID> controllerUuids = new HashSet<>();
516 controllerUuids.add(UUID.uuid(controllerUuid)); 617 controllerUuids.add(UUID.uuid(controllerUuid));
517 - bridge.setController(controllerUuids); 618 + bridge.setController(OvsdbSet.ovsdbSet(controllerUuids));
518 updateConfig(OvsdbConstant.CONTROLLER, "_uuid", bridgeUuid, bridge.getRow()); 619 updateConfig(OvsdbConstant.CONTROLLER, "_uuid", bridgeUuid, bridge.getRow());
519 620
520 } 621 }
521 } 622 }
522 -
523 } 623 }
524 624
525 @Override 625 @Override
...@@ -633,7 +733,6 @@ public class DefaultOvsdbClient ...@@ -633,7 +733,6 @@ public class DefaultOvsdbClient
633 * @param childUuid child row uuid 733 * @param childUuid child row uuid
634 * @param parentTableName parent table name 734 * @param parentTableName parent table name
635 * @param parentColumnName parent column 735 * @param parentColumnName parent column
636 - *
637 */ 736 */
638 private void deleteConfig(String childTableName, String childColumnName, 737 private void deleteConfig(String childTableName, String childColumnName,
639 String childUuid, String parentTableName, 738 String childUuid, String parentTableName,
...@@ -676,7 +775,6 @@ public class DefaultOvsdbClient ...@@ -676,7 +775,6 @@ public class DefaultOvsdbClient
676 * @param columnName column name 775 * @param columnName column name
677 * @param uuid uuid 776 * @param uuid uuid
678 * @param row the config data 777 * @param row the config data
679 - *
680 */ 778 */
681 private void updateConfig(String tableName, String columnName, String uuid, 779 private void updateConfig(String tableName, String columnName, String uuid,
682 Row row) { 780 Row row) {
...@@ -704,7 +802,6 @@ public class DefaultOvsdbClient ...@@ -704,7 +802,6 @@ public class DefaultOvsdbClient
704 * @param parentColumnName parent column 802 * @param parentColumnName parent column
705 * @param parentUuid parent uuid 803 * @param parentUuid parent uuid
706 * @param row the config data 804 * @param row the config data
707 - *
708 * @return uuid, empty if no uuid is find 805 * @return uuid, empty if no uuid is find
709 */ 806 */
710 private String insertConfig(String childTableName, String childColumnName, 807 private String insertConfig(String childTableName, String childColumnName,
...@@ -773,7 +870,6 @@ public class DefaultOvsdbClient ...@@ -773,7 +870,6 @@ public class DefaultOvsdbClient
773 * 870 *
774 * @param tableName ovsdb table interface 871 * @param tableName ovsdb table interface
775 * @param portRow row of port 872 * @param portRow row of port
776 - *
777 * @return insert, empty if null 873 * @return insert, empty if null
778 */ 874 */
779 private Insert handlePortInsertTable(String tableName, Row portRow) { 875 private Insert handlePortInsertTable(String tableName, Row portRow) {
...@@ -802,7 +898,6 @@ public class DefaultOvsdbClient ...@@ -802,7 +898,6 @@ public class DefaultOvsdbClient
802 * 898 *
803 * @param tunnelType 899 * @param tunnelType
804 * @param dstIp the remote ip address 900 * @param dstIp the remote ip address
805 - *
806 * @return tunnel name 901 * @return tunnel name
807 */ 902 */
808 private String getTunnelName(String tunnelType, IpAddress dstIp) { 903 private String getTunnelName(String tunnelType, IpAddress dstIp) {
...@@ -877,10 +972,7 @@ public class DefaultOvsdbClient ...@@ -877,10 +972,7 @@ public class DefaultOvsdbClient
877 } 972 }
878 DatabaseSchema dbSchema = schema.get(dbName); 973 DatabaseSchema dbSchema = schema.get(dbName);
879 if (dbSchema != null) { 974 if (dbSchema != null) {
880 - Function<List<JsonNode>, List<OperationResult>> rowFunction = 975 + Function<List<JsonNode>, List<OperationResult>> rowFunction = (input -> {
881 - new Function<List<JsonNode>, List<OperationResult>>() {
882 - @Override
883 - public List<OperationResult> apply(List<JsonNode> input) {
884 log.info("Get ovsdb operation result"); 976 log.info("Get ovsdb operation result");
885 List<OperationResult> result = FromJsonUtil 977 List<OperationResult> result = FromJsonUtil
886 .jsonNodeToOperationResult(input, operations); 978 .jsonNodeToOperationResult(input, operations);
...@@ -890,8 +982,7 @@ public class DefaultOvsdbClient ...@@ -890,8 +982,7 @@ public class DefaultOvsdbClient
890 return null; 982 return null;
891 } 983 }
892 return result; 984 return result;
893 - } 985 + });
894 - };
895 return Futures.transform(transact(dbSchema, operations), 986 return Futures.transform(transact(dbSchema, operations),
896 rowFunction); 987 rowFunction);
897 } 988 }
...@@ -972,7 +1063,7 @@ public class DefaultOvsdbClient ...@@ -972,7 +1063,7 @@ public class DefaultOvsdbClient
972 1063
973 } 1064 }
974 1065
975 - @SuppressWarnings({ "rawtypes", "unchecked" }) 1066 + @SuppressWarnings({"rawtypes", "unchecked"})
976 @Override 1067 @Override
977 public void processResult(JsonNode response) { 1068 public void processResult(JsonNode response) {
978 log.debug("Handle result"); 1069 log.debug("Handle result");
...@@ -1042,6 +1133,105 @@ public class DefaultOvsdbClient ...@@ -1042,6 +1133,105 @@ public class DefaultOvsdbClient
1042 } 1133 }
1043 1134
1044 @Override 1135 @Override
1136 + public Set<ControllerInfo> getControllers(DeviceId openflowDeviceId) {
1137 + UUID bridgeUuid = getBridgeUUID(openflowDeviceId);
1138 + if (bridgeUuid == null) {
1139 + log.warn("bad bridge Uuid");
1140 + return null;
1141 + }
1142 + List<Controller> controllers = getControllers(bridgeUuid);
1143 + if (controllers == null) {
1144 + log.warn("bad list of controllers");
1145 + return null;
1146 + }
1147 + return controllers.stream().
1148 + map(controller -> new ControllerInfo(
1149 + (String) controller.getTargetColumn()
1150 + .data())).collect(Collectors.toSet());
1151 + }
1152 +
1153 + private List<Controller> getControllers(UUID bridgeUuid) {
1154 + DatabaseSchema dbSchema = schema.get(OvsdbConstant.DATABASENAME);
1155 + if (dbSchema == null) {
1156 + return null;
1157 + }
1158 + OvsdbRowStore rowStore = getRowStore(OvsdbConstant.DATABASENAME,
1159 + OvsdbConstant.BRIDGE);
1160 + if (rowStore == null) {
1161 + log.debug("There is no bridge table");
1162 + return null;
1163 + }
1164 +
1165 + Row bridgeRow = rowStore.getRow(bridgeUuid.value());
1166 + Bridge bridge = (Bridge) TableGenerator.
1167 + getTable(dbSchema, bridgeRow, OvsdbTable.BRIDGE);
1168 +
1169 + //FIXME remove log
1170 + log.warn("type of controller column", bridge.getControllerColumn()
1171 + .data().getClass());
1172 + Set<UUID> controllerUuids = (Set<UUID>) ((OvsdbSet) bridge
1173 + .getControllerColumn().data()).set();
1174 +// Set<String> controllerUuidStrings = (Set<String>) bridge.getControllerColumn().data();
1175 +
1176 + OvsdbRowStore controllerRowStore = getRowStore(OvsdbConstant.DATABASENAME,
1177 + OvsdbConstant.CONTROLLER);
1178 + if (controllerRowStore == null) {
1179 + log.debug("There is no controller table");
1180 + return null;
1181 + }
1182 +
1183 + List<Controller> ovsdbControllers = new ArrayList<>();
1184 + ConcurrentMap<String, Row> controllerTableRows = controllerRowStore.getRowStore();
1185 + controllerTableRows.forEach((key, row) -> {
1186 + if (!controllerUuids.contains(UUID.uuid(key))) {
1187 + return;
1188 + }
1189 + Controller controller = (Controller) TableGenerator
1190 + .getTable(dbSchema, row, OvsdbTable.CONTROLLER);
1191 + ovsdbControllers.add(controller);
1192 + });
1193 + return ovsdbControllers;
1194 + }
1195 +
1196 +
1197 + private UUID getBridgeUUID(DeviceId openflowDeviceId) {
1198 + DatabaseSchema dbSchema = schema.get(OvsdbConstant.DATABASENAME);
1199 + if (dbSchema == null) {
1200 + return null;
1201 + }
1202 + OvsdbRowStore rowStore = getRowStore(OvsdbConstant.DATABASENAME,
1203 + OvsdbConstant.BRIDGE);
1204 + if (rowStore == null) {
1205 + log.debug("There is no bridge table");
1206 + return null;
1207 + }
1208 +
1209 + ConcurrentMap<String, Row> bridgeTableRows = rowStore.getRowStore();
1210 + final AtomicReference<UUID> uuid = new AtomicReference<>();
1211 + for (Map.Entry<String, Row> entry : bridgeTableRows.entrySet()) {
1212 + Bridge b = (Bridge) TableGenerator.getTable(dbSchema,
1213 + entry.getValue(),
1214 + OvsdbTable.BRIDGE);
1215 + if (matchesDpid(b, openflowDeviceId)) {
1216 + uuid.set(UUID.uuid(entry.getKey()));
1217 + break;
1218 + }
1219 + }
1220 + if (uuid.get() == null) {
1221 + log.debug("There is no bridge for {}", openflowDeviceId);
1222 + }
1223 + return uuid.get();
1224 +
1225 + }
1226 +
1227 + private static boolean matchesDpid(Bridge b, DeviceId deviceId) {
1228 + String ofDpid = deviceId.toString().replace("of:", "");
1229 + Set ofDeviceIds = ((OvsdbSet) b.getDatapathIdColumn().data()).set();
1230 + //TODO Set<String>
1231 + return ofDeviceIds.contains(ofDpid);
1232 + }
1233 +
1234 + @Override
1045 public Set<OvsdbPort> getPorts() { 1235 public Set<OvsdbPort> getPorts() {
1046 Set<OvsdbPort> ovsdbPorts = new HashSet<OvsdbPort>(); 1236 Set<OvsdbPort> ovsdbPorts = new HashSet<OvsdbPort>();
1047 OvsdbTableStore tableStore = getTableStore(OvsdbConstant.DATABASENAME); 1237 OvsdbTableStore tableStore = getTableStore(OvsdbConstant.DATABASENAME);
......
1 +/*
2 + * Copyright 2015 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +
17 +package org.onosproject.ovsdb.controller.driver;
18 +
19 +import com.fasterxml.jackson.databind.JsonNode;
20 +import com.google.common.util.concurrent.ListenableFuture;
21 +import org.onlab.packet.IpAddress;
22 +import org.onosproject.net.DeviceId;
23 +import org.onosproject.net.behaviour.ControllerInfo;
24 +import org.onosproject.ovsdb.controller.OvsdbBridge;
25 +import org.onosproject.ovsdb.controller.OvsdbClientService;
26 +import org.onosproject.ovsdb.controller.OvsdbNodeId;
27 +import org.onosproject.ovsdb.controller.OvsdbPort;
28 +import org.onosproject.ovsdb.controller.OvsdbTunnel;
29 +import org.onosproject.ovsdb.rfc.message.OperationResult;
30 +import org.onosproject.ovsdb.rfc.message.TableUpdates;
31 +import org.onosproject.ovsdb.rfc.notation.Row;
32 +import org.onosproject.ovsdb.rfc.notation.UUID;
33 +import org.onosproject.ovsdb.rfc.operations.Operation;
34 +import org.onosproject.ovsdb.rfc.schema.DatabaseSchema;
35 +
36 +import java.util.List;
37 +import java.util.Set;
38 +
39 +/**
40 + * Test Adapter for OvsdbClientService.
41 + */
42 +public class OvsdbClientServiceAdapter implements OvsdbClientService {
43 +
44 + @Override
45 + public OvsdbNodeId nodeId() {
46 + return null;
47 + }
48 +
49 + @Override
50 + public void createTunnel(IpAddress srcIp, IpAddress dstIp) {
51 +
52 + }
53 +
54 + @Override
55 + public void dropTunnel(IpAddress srcIp, IpAddress dstIp) {
56 +
57 + }
58 +
59 + @Override
60 + public Set<OvsdbTunnel> getTunnels() {
61 + return null;
62 + }
63 +
64 + @Override
65 + public void createBridge(String bridgeName) {
66 +
67 + }
68 +
69 + @Override
70 + public void dropBridge(String bridgeName) {
71 +
72 + }
73 +
74 + @Override
75 + public Set<OvsdbBridge> getBridges() {
76 + return null;
77 + }
78 +
79 + @Override
80 + public Set<ControllerInfo> getControllers(DeviceId openflowDeviceId) {
81 + return null;
82 + }
83 +
84 + @Override
85 + public void setControllersWithUUID(UUID bridgeUuid, List<ControllerInfo> controllers) {
86 +
87 + }
88 +
89 + @Override
90 + public void setControllersWithDeviceId(DeviceId deviceId, List<ControllerInfo> controllers) {
91 +
92 + }
93 +
94 + @Override
95 + public void createPort(String bridgeName, String portName) {
96 +
97 + }
98 +
99 + @Override
100 + public void dropPort(String bridgeName, String portName) {
101 +
102 + }
103 +
104 + @Override
105 + public Set<OvsdbPort> getPorts() {
106 + return null;
107 + }
108 +
109 + @Override
110 + public boolean isConnected() {
111 + return false;
112 + }
113 +
114 + @Override
115 + public String getBridgeUuid(String bridgeName) {
116 + return null;
117 + }
118 +
119 + @Override
120 + public String getPortUuid(String portName, String bridgeUuid) {
121 + return null;
122 + }
123 +
124 + @Override
125 + public String getInterfaceUuid(String portUuid, String portName) {
126 + return null;
127 + }
128 +
129 + @Override
130 + public String getControllerUuid(String controllerName, String controllerTarget) {
131 + return null;
132 + }
133 +
134 + @Override
135 + public String getOvsUuid(String dbName) {
136 + return null;
137 + }
138 +
139 + @Override
140 + public ListenableFuture<DatabaseSchema> getOvsdbSchema(String dbName) {
141 + return null;
142 + }
143 +
144 + @Override
145 + public ListenableFuture<TableUpdates> monitorTables(String dbName, String id) {
146 + return null;
147 + }
148 +
149 + @Override
150 + public ListenableFuture<List<OperationResult>> transactConfig(String dbName, List<Operation> operations) {
151 + return null;
152 + }
153 +
154 + @Override
155 + public DatabaseSchema getDatabaseSchema(String dbName) {
156 + return null;
157 + }
158 +
159 + @Override
160 + public Row getRow(String dbName, String tableName, String uuid) {
161 + return null;
162 + }
163 +
164 + @Override
165 + public void removeRow(String dbName, String tableName, String uuid) {
166 +
167 + }
168 +
169 + @Override
170 + public void updateOvsdbStore(String dbName, String tableName, String uuid, Row row) {
171 +
172 + }
173 +
174 + @Override
175 + public Set<OvsdbPort> getLocalPorts(Iterable<String> ifaceids) {
176 + return null;
177 + }
178 +
179 + @Override
180 + public void disconnect() {
181 +
182 + }
183 +
184 + @Override
185 + public ListenableFuture<JsonNode> getSchema(List<String> dbnames) {
186 + return null;
187 + }
188 +
189 + @Override
190 + public ListenableFuture<List<String>> echo() {
191 + return null;
192 + }
193 +
194 + @Override
195 + public ListenableFuture<JsonNode> monitor(DatabaseSchema dbSchema, String monitorId) {
196 + return null;
197 + }
198 +
199 + @Override
200 + public ListenableFuture<List<String>> listDbs() {
201 + return null;
202 + }
203 +
204 + @Override
205 + public ListenableFuture<List<JsonNode>> transact(DatabaseSchema dbSchema, List<Operation> operations) {
206 + return null;
207 + }
208 +}
1 +/*
2 + * Copyright 2015 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +
17 +package org.onosproject.ovsdb.controller.driver;
18 +
19 +import org.onlab.packet.IpAddress;
20 +import org.onlab.packet.TpPort;
21 +import org.onosproject.ovsdb.controller.OvsdbClientService;
22 +import org.onosproject.ovsdb.controller.OvsdbController;
23 +import org.onosproject.ovsdb.controller.OvsdbEventListener;
24 +import org.onosproject.ovsdb.controller.OvsdbNodeId;
25 +import org.onosproject.ovsdb.controller.OvsdbNodeListener;
26 +
27 +import java.util.ArrayList;
28 +import java.util.Arrays;
29 +import java.util.List;
30 +import java.util.concurrent.ConcurrentHashMap;
31 +
32 +/**
33 + * Test Adapter for OvsdbController.
34 + */
35 +public class OvsdbControllerAdapter implements OvsdbController {
36 + protected ConcurrentHashMap<OvsdbNodeId, OvsdbClientServiceAdapter> ovsdbClients =
37 + new ConcurrentHashMap<OvsdbNodeId, OvsdbClientServiceAdapter>();
38 +
39 + @Override
40 + public void addNodeListener(OvsdbNodeListener listener) {
41 +
42 + }
43 +
44 + @Override
45 + public void removeNodeListener(OvsdbNodeListener listener) {
46 +
47 + }
48 +
49 + @Override
50 + public void addOvsdbEventListener(OvsdbEventListener listener) {
51 +
52 + }
53 +
54 + @Override
55 + public void removeOvsdbEventListener(OvsdbEventListener listener) {
56 +
57 + }
58 +
59 + @Override
60 + public List<OvsdbNodeId> getNodeIds() {
61 + long port = 6653;
62 + return new ArrayList<OvsdbNodeId>(Arrays.asList(
63 + new OvsdbNodeId(IpAddress.valueOf("127.0.0.1"), port)));
64 + }
65 +
66 + @Override
67 + public OvsdbClientService getOvsdbClient(OvsdbNodeId nodeId) {
68 + return ovsdbClients.get(nodeId);
69 + }
70 +
71 + @Override
72 + public void connect(IpAddress ip, TpPort port) {
73 +
74 + }
75 +}
...@@ -15,18 +15,8 @@ ...@@ -15,18 +15,8 @@
15 */ 15 */
16 package org.onosproject.ovsdb.controller.impl; 16 package org.onosproject.ovsdb.controller.impl;
17 17
18 -import static com.google.common.base.Preconditions.checkNotNull; 18 +import com.fasterxml.jackson.databind.JsonNode;
19 - 19 +import com.google.common.collect.ImmutableList;
20 -import java.math.BigInteger;
21 -import java.util.HashSet;
22 -import java.util.Iterator;
23 -import java.util.List;
24 -import java.util.Map;
25 -import java.util.Set;
26 -import java.util.concurrent.ConcurrentHashMap;
27 -import java.util.concurrent.CopyOnWriteArraySet;
28 -import java.util.concurrent.ExecutionException;
29 -
30 import org.apache.felix.scr.annotations.Activate; 20 import org.apache.felix.scr.annotations.Activate;
31 import org.apache.felix.scr.annotations.Component; 21 import org.apache.felix.scr.annotations.Component;
32 import org.apache.felix.scr.annotations.Deactivate; 22 import org.apache.felix.scr.annotations.Deactivate;
...@@ -68,7 +58,17 @@ import org.osgi.service.component.ComponentContext; ...@@ -68,7 +58,17 @@ import org.osgi.service.component.ComponentContext;
68 import org.slf4j.Logger; 58 import org.slf4j.Logger;
69 import org.slf4j.LoggerFactory; 59 import org.slf4j.LoggerFactory;
70 60
71 -import com.fasterxml.jackson.databind.JsonNode; 61 +import java.math.BigInteger;
62 +import java.util.HashSet;
63 +import java.util.Iterator;
64 +import java.util.List;
65 +import java.util.Map;
66 +import java.util.Set;
67 +import java.util.concurrent.ConcurrentHashMap;
68 +import java.util.concurrent.CopyOnWriteArraySet;
69 +import java.util.concurrent.ExecutionException;
70 +
71 +import static com.google.common.base.Preconditions.checkNotNull;
72 72
73 /** 73 /**
74 * The implementation of OvsdbController. 74 * The implementation of OvsdbController.
...@@ -134,8 +134,7 @@ public class OvsdbControllerImpl implements OvsdbController { ...@@ -134,8 +134,7 @@ public class OvsdbControllerImpl implements OvsdbController {
134 134
135 @Override 135 @Override
136 public List<OvsdbNodeId> getNodeIds() { 136 public List<OvsdbNodeId> getNodeIds() {
137 - // TODO Auto-generated method stub 137 + return ImmutableList.copyOf(ovsdbClients.keySet());
138 - return null;
139 } 138 }
140 139
141 @Override 140 @Override
...@@ -315,7 +314,7 @@ public class OvsdbControllerImpl implements OvsdbController { ...@@ -315,7 +314,7 @@ public class OvsdbControllerImpl implements OvsdbController {
315 314
316 String attachedMac = externalIds.get(OvsdbConstant.EXTERNAL_ID_VM_MAC); 315 String attachedMac = externalIds.get(OvsdbConstant.EXTERNAL_ID_VM_MAC);
317 if (attachedMac == null) { 316 if (attachedMac == null) {
318 - log.warn("The attachedMac is null"); 317 + log.debug("The attachedMac is null"); //FIXME why always null?
319 return null; 318 return null;
320 } 319 }
321 String ifaceid = externalIds 320 String ifaceid = externalIds
...@@ -324,7 +323,7 @@ public class OvsdbControllerImpl implements OvsdbController { ...@@ -324,7 +323,7 @@ public class OvsdbControllerImpl implements OvsdbController {
324 log.warn("The ifaceid is null"); 323 log.warn("The ifaceid is null");
325 return null; 324 return null;
326 } 325 }
327 - return new String[] {attachedMac, ifaceid}; 326 + return new String[]{attachedMac, ifaceid};
328 } 327 }
329 328
330 /** 329 /**
......
...@@ -15,20 +15,21 @@ ...@@ -15,20 +15,21 @@
15 */ 15 */
16 package org.onosproject.ovsdb.rfc.notation; 16 package org.onosproject.ovsdb.rfc.notation;
17 17
18 -import static com.google.common.base.MoreObjects.toStringHelper; 18 +import com.google.common.collect.Maps;
19 -import static com.google.common.base.Preconditions.checkNotNull;
20 19
21 import java.util.Collection; 20 import java.util.Collection;
22 import java.util.Map; 21 import java.util.Map;
23 import java.util.Objects; 22 import java.util.Objects;
24 23
25 -import com.google.common.collect.Maps; 24 +import static com.google.common.base.MoreObjects.toStringHelper;
25 +import static com.google.common.base.Preconditions.checkNotNull;
26 26
27 /** 27 /**
28 * Row is the basic element of the OpenVswitch's table. 28 * Row is the basic element of the OpenVswitch's table.
29 */ 29 */
30 public final class Row { 30 public final class Row {
31 private String tableName; 31 private String tableName;
32 + private UUID uuid;
32 private Map<String, Column> columns; 33 private Map<String, Column> columns;
33 34
34 /** 35 /**
...@@ -40,9 +41,11 @@ public final class Row { ...@@ -40,9 +41,11 @@ public final class Row {
40 41
41 /** 42 /**
42 * Row constructor. 43 * Row constructor.
44 + *
43 * @param tableName table name 45 * @param tableName table name
44 */ 46 */
45 - public Row(String tableName) { 47 + @Deprecated
48 + private Row(String tableName) {
46 checkNotNull(tableName, "tableName cannot be null"); 49 checkNotNull(tableName, "tableName cannot be null");
47 this.tableName = tableName; 50 this.tableName = tableName;
48 this.columns = Maps.newHashMap(); 51 this.columns = Maps.newHashMap();
...@@ -50,18 +53,22 @@ public final class Row { ...@@ -50,18 +53,22 @@ public final class Row {
50 53
51 /** 54 /**
52 * Row constructor. 55 * Row constructor.
56 + *
53 * @param tableName table name 57 * @param tableName table name
54 * @param columns Map of Column entity 58 * @param columns Map of Column entity
55 */ 59 */
56 - public Row(String tableName, Map<String, Column> columns) { 60 + public Row(String tableName, UUID uuid, Map<String, Column> columns) {
57 checkNotNull(tableName, "table name cannot be null"); 61 checkNotNull(tableName, "table name cannot be null");
62 + checkNotNull(uuid, "uuid cannot be null");
58 checkNotNull(columns, "columns cannot be null"); 63 checkNotNull(columns, "columns cannot be null");
59 this.tableName = tableName; 64 this.tableName = tableName;
65 + this.uuid = uuid;
60 this.columns = columns; 66 this.columns = columns;
61 } 67 }
62 68
63 /** 69 /**
64 * Returns tableName. 70 * Returns tableName.
71 + *
65 * @return tableName 72 * @return tableName
66 */ 73 */
67 public String tableName() { 74 public String tableName() {
...@@ -70,6 +77,7 @@ public final class Row { ...@@ -70,6 +77,7 @@ public final class Row {
70 77
71 /** 78 /**
72 * Set tableName value. 79 * Set tableName value.
80 + *
73 * @param tableName table name 81 * @param tableName table name
74 */ 82 */
75 public void setTableName(String tableName) { 83 public void setTableName(String tableName) {
...@@ -77,7 +85,26 @@ public final class Row { ...@@ -77,7 +85,26 @@ public final class Row {
77 } 85 }
78 86
79 /** 87 /**
88 + * Returns uuid.
89 + *
90 + * @return uuid
91 + */
92 + public UUID uuid() {
93 + return uuid;
94 + }
95 +
96 + /**
97 + * Sets uuid value.
98 + *
99 + * @param uuid new uuid
100 + */
101 + public void setUuid(UUID uuid) {
102 + this.uuid = uuid;
103 + }
104 +
105 + /**
80 * Returns Column by ColumnSchema. 106 * Returns Column by ColumnSchema.
107 + *
81 * @param columnName column name 108 * @param columnName column name
82 * @return Column 109 * @return Column
83 */ 110 */
...@@ -87,6 +114,7 @@ public final class Row { ...@@ -87,6 +114,7 @@ public final class Row {
87 114
88 /** 115 /**
89 * Returns Collection of Column. 116 * Returns Collection of Column.
117 + *
90 * @return Collection of Column 118 * @return Collection of Column
91 */ 119 */
92 public Collection<Column> getColumns() { 120 public Collection<Column> getColumns() {
...@@ -95,6 +123,7 @@ public final class Row { ...@@ -95,6 +123,7 @@ public final class Row {
95 123
96 /** 124 /**
97 * add Column. 125 * add Column.
126 + *
98 * @param columnName column name 127 * @param columnName column name
99 * @param data Column entity 128 * @param data Column entity
100 */ 129 */
......
...@@ -15,16 +15,17 @@ ...@@ -15,16 +15,17 @@
15 */ 15 */
16 package org.onosproject.ovsdb.rfc.table; 16 package org.onosproject.ovsdb.rfc.table;
17 17
18 -import java.util.Map;
19 -import java.util.Set;
20 -
21 import org.onosproject.ovsdb.rfc.notation.Column; 18 import org.onosproject.ovsdb.rfc.notation.Column;
19 +import org.onosproject.ovsdb.rfc.notation.OvsdbSet;
22 import org.onosproject.ovsdb.rfc.notation.Row; 20 import org.onosproject.ovsdb.rfc.notation.Row;
23 import org.onosproject.ovsdb.rfc.notation.UUID; 21 import org.onosproject.ovsdb.rfc.notation.UUID;
24 import org.onosproject.ovsdb.rfc.schema.DatabaseSchema; 22 import org.onosproject.ovsdb.rfc.schema.DatabaseSchema;
25 import org.onosproject.ovsdb.rfc.tableservice.AbstractOvsdbTableService; 23 import org.onosproject.ovsdb.rfc.tableservice.AbstractOvsdbTableService;
26 import org.onosproject.ovsdb.rfc.tableservice.ColumnDescription; 24 import org.onosproject.ovsdb.rfc.tableservice.ColumnDescription;
27 25
26 +import java.util.Map;
27 +import java.util.Set;
28 +
28 /** 29 /**
29 * This class provides operations of Bridge Table. 30 * This class provides operations of Bridge Table.
30 */ 31 */
...@@ -351,7 +352,7 @@ public class Bridge extends AbstractOvsdbTableService { ...@@ -351,7 +352,7 @@ public class Bridge extends AbstractOvsdbTableService {
351 * of attributes. 352 * of attributes.
352 * @param controller the column data which column name is "controller" 353 * @param controller the column data which column name is "controller"
353 */ 354 */
354 - public void setController(Set<UUID> controller) { 355 + public void setController(OvsdbSet controller) {
355 ColumnDescription columndesc = new ColumnDescription( 356 ColumnDescription columndesc = new ColumnDescription(
356 BridgeColumn.CONTROLLER 357 BridgeColumn.CONTROLLER
357 .columnName(), 358 .columnName(),
......
...@@ -37,6 +37,7 @@ public final class TableGenerator { ...@@ -37,6 +37,7 @@ public final class TableGenerator {
37 * @param tableName table name 37 * @param tableName table name
38 * @return Object table entity 38 * @return Object table entity
39 */ 39 */
40 + //FIXME change the name, it creates a row object, such as a controller.
40 public static Object createTable(DatabaseSchema dbSchema, 41 public static Object createTable(DatabaseSchema dbSchema,
41 OvsdbTable tableName) { 42 OvsdbTable tableName) {
42 Row row = new Row(); 43 Row row = new Row();
......
...@@ -15,12 +15,11 @@ ...@@ -15,12 +15,11 @@
15 */ 15 */
16 package org.onosproject.ovsdb.rfc.utils; 16 package org.onosproject.ovsdb.rfc.utils;
17 17
18 -import java.util.ArrayList; 18 +import com.fasterxml.jackson.core.JsonProcessingException;
19 -import java.util.HashMap; 19 +import com.fasterxml.jackson.databind.JsonNode;
20 -import java.util.Iterator; 20 +import com.fasterxml.jackson.databind.ObjectMapper;
21 -import java.util.List; 21 +import com.google.common.collect.Lists;
22 -import java.util.Map; 22 +import com.google.common.collect.Maps;
23 -
24 import org.onosproject.ovsdb.rfc.exception.AbnormalJsonNodeException; 23 import org.onosproject.ovsdb.rfc.exception.AbnormalJsonNodeException;
25 import org.onosproject.ovsdb.rfc.exception.UnsupportedException; 24 import org.onosproject.ovsdb.rfc.exception.UnsupportedException;
26 import org.onosproject.ovsdb.rfc.jsonrpc.Callback; 25 import org.onosproject.ovsdb.rfc.jsonrpc.Callback;
...@@ -41,11 +40,11 @@ import org.onosproject.ovsdb.rfc.schema.type.ColumnTypeFactory; ...@@ -41,11 +40,11 @@ import org.onosproject.ovsdb.rfc.schema.type.ColumnTypeFactory;
41 import org.slf4j.Logger; 40 import org.slf4j.Logger;
42 import org.slf4j.LoggerFactory; 41 import org.slf4j.LoggerFactory;
43 42
44 -import com.fasterxml.jackson.core.JsonProcessingException; 43 +import java.util.ArrayList;
45 -import com.fasterxml.jackson.databind.JsonNode; 44 +import java.util.HashMap;
46 -import com.fasterxml.jackson.databind.ObjectMapper; 45 +import java.util.Iterator;
47 -import com.google.common.collect.Lists; 46 +import java.util.List;
48 -import com.google.common.collect.Maps; 47 +import java.util.Map;
49 48
50 /** 49 /**
51 * JsonNode utility class. convert JsonNode into Object. 50 * JsonNode utility class. convert JsonNode into Object.
...@@ -247,7 +246,7 @@ public final class FromJsonUtil { ...@@ -247,7 +246,7 @@ public final class FromJsonUtil {
247 validateJsonNode(rowsNode, "rows"); 246 validateJsonNode(rowsNode, "rows");
248 ArrayList<Row> rows = Lists.newArrayList(); 247 ArrayList<Row> rows = Lists.newArrayList();
249 for (JsonNode rowNode : rowsNode.get("rows")) { 248 for (JsonNode rowNode : rowsNode.get("rows")) {
250 - rows.add(createRow(tableSchema, rowNode)); 249 + rows.add(createRow(tableSchema, null, rowNode)); //FIXME null will throw exception
251 } 250 }
252 return rows; 251 return rows;
253 } 252 }
...@@ -285,8 +284,8 @@ public final class FromJsonUtil { ...@@ -285,8 +284,8 @@ public final class FromJsonUtil {
285 UUID uuid = UUID.uuid(uuidStr); 284 UUID uuid = UUID.uuid(uuidStr);
286 JsonNode newR = oldNewRow.getValue().get("new"); 285 JsonNode newR = oldNewRow.getValue().get("new");
287 JsonNode oldR = oldNewRow.getValue().get("old"); 286 JsonNode oldR = oldNewRow.getValue().get("old");
288 - Row newRow = newR != null ? createRow(tableSchema, newR) : null; 287 + Row newRow = newR != null ? createRow(tableSchema, uuid, newR) : null;
289 - Row oldRow = oldR != null ? createRow(tableSchema, oldR) : null; 288 + Row oldRow = oldR != null ? createRow(tableSchema, uuid, oldR) : null;
290 RowUpdate rowUpdate = new RowUpdate(uuid, oldRow, newRow); 289 RowUpdate rowUpdate = new RowUpdate(uuid, oldRow, newRow);
291 rows.put(uuid, rowUpdate); 290 rows.put(uuid, rowUpdate);
292 } 291 }
...@@ -299,7 +298,7 @@ public final class FromJsonUtil { ...@@ -299,7 +298,7 @@ public final class FromJsonUtil {
299 * @param rowNode JsonNode 298 * @param rowNode JsonNode
300 * @return Row 299 * @return Row
301 */ 300 */
302 - private static Row createRow(TableSchema tableSchema, JsonNode rowNode) { 301 + private static Row createRow(TableSchema tableSchema, UUID uuid, JsonNode rowNode) {
303 if (tableSchema == null) { 302 if (tableSchema == null) {
304 return null; 303 return null;
305 } 304 }
...@@ -314,7 +313,7 @@ public final class FromJsonUtil { ...@@ -314,7 +313,7 @@ public final class FromJsonUtil {
314 columns.put(columnName, new Column(columnName, obj)); 313 columns.put(columnName, new Column(columnName, obj));
315 } 314 }
316 } 315 }
317 - return new Row(tableSchema.name(), columns); 316 + return new Row(tableSchema.name(), uuid, columns);
318 } 317 }
319 318
320 } 319 }
......
...@@ -8,4 +8,4 @@ export OCN="10.128.12.4" ...@@ -8,4 +8,4 @@ export OCN="10.128.12.4"
8 8
9 export OCT=$OC1 9 export OCT=$OC1
10 export ONOS_USE_SSH=true 10 export ONOS_USE_SSH=true
11 -export ONOS_APPS=drivers,openflow,proxyarp,mobility 11 +export ONOS_APPS=drivers,openflow,proxyarp,ovsdb
......