Committed by
Gerrit Code Review
Inserted set and get controllers methods in ovsdb controller config
Change-Id: I791ff2ae159d0ac50beff22abda2b187913428f6
Showing
21 changed files
with
975 additions
and
85 deletions
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,8 +55,8 @@ | ... | @@ -55,8 +55,8 @@ |
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> |
62 | <artifactId>onos-ovsdb-api</artifactId> | 62 | <artifactId>onos-ovsdb-api</artifactId> |
... | @@ -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,10 +86,33 @@ public interface OvsdbClientService extends OvsdbRPC { | ... | @@ -85,10 +86,33 @@ 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 |
91 | - * @param portName port name | 115 | + * @param portName port name |
92 | */ | 116 | */ |
93 | void createPort(String bridgeName, String portName); | 117 | void createPort(String bridgeName, String portName); |
94 | 118 | ||
... | @@ -96,7 +120,7 @@ public interface OvsdbClientService extends OvsdbRPC { | ... | @@ -96,7 +120,7 @@ public interface OvsdbClientService extends OvsdbRPC { |
96 | * Drops a port. | 120 | * Drops a port. |
97 | * | 121 | * |
98 | * @param bridgeName bridge name | 122 | * @param bridgeName bridge name |
99 | - * @param portName port name | 123 | + * @param portName port name |
100 | */ | 124 | */ |
101 | void dropPort(String bridgeName, String portName); | 125 | void dropPort(String bridgeName, String portName); |
102 | 126 | ||
... | @@ -125,7 +149,7 @@ public interface OvsdbClientService extends OvsdbRPC { | ... | @@ -125,7 +149,7 @@ public interface OvsdbClientService extends OvsdbRPC { |
125 | /** | 149 | /** |
126 | * Gets the Port uuid. | 150 | * Gets the Port uuid. |
127 | * | 151 | * |
128 | - * @param portName port name | 152 | + * @param portName port name |
129 | * @param bridgeUuid bridge uuid | 153 | * @param bridgeUuid bridge uuid |
130 | * @return port uuid, empty if no uuid is find | 154 | * @return port uuid, empty if no uuid is find |
131 | */ | 155 | */ |
... | @@ -143,7 +167,7 @@ public interface OvsdbClientService extends OvsdbRPC { | ... | @@ -143,7 +167,7 @@ public interface OvsdbClientService extends OvsdbRPC { |
143 | /** | 167 | /** |
144 | * Gets the Controller uuid. | 168 | * Gets the Controller uuid. |
145 | * | 169 | * |
146 | - * @param controllerName controller name | 170 | + * @param controllerName controller name |
147 | * @param controllerTarget controller target | 171 | * @param controllerTarget controller target |
148 | * @return controller uuid, empty if no uuid is find | 172 | * @return controller uuid, empty if no uuid is find |
149 | */ | 173 | */ |
... | @@ -169,7 +193,7 @@ public interface OvsdbClientService extends OvsdbRPC { | ... | @@ -169,7 +193,7 @@ public interface OvsdbClientService extends OvsdbRPC { |
169 | * Gets the ovsdb table updates. | 193 | * Gets the ovsdb table updates. |
170 | * | 194 | * |
171 | * @param dbName database name | 195 | * @param dbName database name |
172 | - * @param id random uuid | 196 | + * @param id random uuid |
173 | * @return table updates | 197 | * @return table updates |
174 | */ | 198 | */ |
175 | ListenableFuture<TableUpdates> monitorTables(String dbName, String id); | 199 | ListenableFuture<TableUpdates> monitorTables(String dbName, String id); |
... | @@ -177,7 +201,7 @@ public interface OvsdbClientService extends OvsdbRPC { | ... | @@ -177,7 +201,7 @@ public interface OvsdbClientService extends OvsdbRPC { |
177 | /** | 201 | /** |
178 | * Gets the ovsdb config operation result. | 202 | * Gets the ovsdb config operation result. |
179 | * | 203 | * |
180 | - * @param dbName database name | 204 | + * @param dbName database name |
181 | * @param operations the list of operations | 205 | * @param operations the list of operations |
182 | * @return operation results | 206 | * @return operation results |
183 | */ | 207 | */ |
... | @@ -187,7 +211,7 @@ public interface OvsdbClientService extends OvsdbRPC { | ... | @@ -187,7 +211,7 @@ public interface OvsdbClientService extends OvsdbRPC { |
187 | /** | 211 | /** |
188 | * Gets the ovsdb database schema from local. | 212 | * Gets the ovsdb database schema from local. |
189 | * | 213 | * |
190 | - * @param dbName database name | 214 | + * @param dbName database name |
191 | * @return database schema | 215 | * @return database schema |
192 | */ | 216 | */ |
193 | DatabaseSchema getDatabaseSchema(String dbName); | 217 | DatabaseSchema getDatabaseSchema(String dbName); |
... | @@ -195,9 +219,9 @@ public interface OvsdbClientService extends OvsdbRPC { | ... | @@ -195,9 +219,9 @@ public interface OvsdbClientService extends OvsdbRPC { |
195 | /** | 219 | /** |
196 | * Gets the ovsdb row from the local ovsdb store. | 220 | * Gets the ovsdb row from the local ovsdb store. |
197 | * | 221 | * |
198 | - * @param dbName database name | 222 | + * @param dbName database name |
199 | * @param tableName table name | 223 | * @param tableName table name |
200 | - * @param uuid row uuid | 224 | + * @param uuid row uuid |
201 | * @return row ovsdb row | 225 | * @return row ovsdb row |
202 | */ | 226 | */ |
203 | Row getRow(String dbName, String tableName, String uuid); | 227 | Row getRow(String dbName, String tableName, String uuid); |
... | @@ -205,19 +229,19 @@ public interface OvsdbClientService extends OvsdbRPC { | ... | @@ -205,19 +229,19 @@ public interface OvsdbClientService extends OvsdbRPC { |
205 | /** | 229 | /** |
206 | * Removes the ovsdb row from the local ovsdb store. | 230 | * Removes the ovsdb row from the local ovsdb store. |
207 | * | 231 | * |
208 | - * @param dbName database name | 232 | + * @param dbName database name |
209 | * @param tableName table name | 233 | * @param tableName table name |
210 | - * @param uuid row uuid | 234 | + * @param uuid row uuid |
211 | */ | 235 | */ |
212 | void removeRow(String dbName, String tableName, String uuid); | 236 | void removeRow(String dbName, String tableName, String uuid); |
213 | 237 | ||
214 | /** | 238 | /** |
215 | * Updates the local ovsdb store. | 239 | * Updates the local ovsdb store. |
216 | * | 240 | * |
217 | - * @param dbName database name | 241 | + * @param dbName database name |
218 | * @param tableName table name | 242 | * @param tableName table name |
219 | - * @param uuid row uuid | 243 | + * @param uuid row uuid |
220 | - * @param row ovsdb row | 244 | + * @param row ovsdb row |
221 | */ | 245 | */ |
222 | void updateOvsdbStore(String dbName, String tableName, String uuid, Row row); | 246 | void updateOvsdbStore(String dbName, String tableName, String uuid, Row row); |
223 | 247 | ... | ... |
This diff is collapsed. Click to expand it.
ovsdb/api/src/test/java/org/onosproject/ovsdb/controller/driver/OvsdbClientServiceAdapter.java
0 → 100644
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 | +} |
ovsdb/api/src/test/java/org/onosproject/ovsdb/controller/driver/OvsdbControllerAdapter.java
0 → 100644
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 |
... | @@ -210,8 +209,8 @@ public class OvsdbControllerImpl implements OvsdbController { | ... | @@ -210,8 +209,8 @@ public class OvsdbControllerImpl implements OvsdbController { |
210 | * Processes table updates. | 209 | * Processes table updates. |
211 | * | 210 | * |
212 | * @param clientService OvsdbClientService instance | 211 | * @param clientService OvsdbClientService instance |
213 | - * @param updates TableUpdates instance | 212 | + * @param updates TableUpdates instance |
214 | - * @param dbName ovsdb database name | 213 | + * @param dbName ovsdb database name |
215 | */ | 214 | */ |
216 | private void processTableUpdates(OvsdbClientService clientService, | 215 | private void processTableUpdates(OvsdbClientService clientService, |
217 | TableUpdates updates, String dbName) | 216 | TableUpdates updates, String dbName) |
... | @@ -242,8 +241,8 @@ public class OvsdbControllerImpl implements OvsdbController { | ... | @@ -242,8 +241,8 @@ public class OvsdbControllerImpl implements OvsdbController { |
242 | Row row = clientService.getRow(OvsdbConstant.DATABASENAME, tableName, uuid.value()); | 241 | Row row = clientService.getRow(OvsdbConstant.DATABASENAME, tableName, uuid.value()); |
243 | dispatchInterfaceEvent(clientService, | 242 | dispatchInterfaceEvent(clientService, |
244 | row, | 243 | row, |
245 | - OvsdbEvent.Type.PORT_REMOVED, | 244 | + OvsdbEvent.Type.PORT_REMOVED, |
246 | - dbSchema); | 245 | + dbSchema); |
247 | } | 246 | } |
248 | clientService.removeRow(dbName, tableName, uuid.value()); | 247 | clientService.removeRow(dbName, tableName, uuid.value()); |
249 | } | 248 | } |
... | @@ -255,10 +254,10 @@ public class OvsdbControllerImpl implements OvsdbController { | ... | @@ -255,10 +254,10 @@ public class OvsdbControllerImpl implements OvsdbController { |
255 | * Dispatches event to the north. | 254 | * Dispatches event to the north. |
256 | * | 255 | * |
257 | * @param clientService OvsdbClientService instance | 256 | * @param clientService OvsdbClientService instance |
258 | - * @param newRow a new row | 257 | + * @param newRow a new row |
259 | - * @param oldRow an old row | 258 | + * @param oldRow an old row |
260 | - * @param eventType type of event | 259 | + * @param eventType type of event |
261 | - * @param dbSchema ovsdb database schema | 260 | + * @param dbSchema ovsdb database schema |
262 | */ | 261 | */ |
263 | private void dispatchInterfaceEvent(OvsdbClientService clientService, | 262 | private void dispatchInterfaceEvent(OvsdbClientService clientService, |
264 | Row row, | 263 | Row row, |
... | @@ -283,13 +282,13 @@ public class OvsdbControllerImpl implements OvsdbController { | ... | @@ -283,13 +282,13 @@ public class OvsdbControllerImpl implements OvsdbController { |
283 | } | 282 | } |
284 | 283 | ||
285 | EventSubject eventSubject = new DefaultEventSubject(MacAddress.valueOf( | 284 | EventSubject eventSubject = new DefaultEventSubject(MacAddress.valueOf( |
286 | - macAndIfaceId[0]), | 285 | + macAndIfaceId[0]), |
287 | new HashSet<IpAddress>(), | 286 | new HashSet<IpAddress>(), |
288 | new OvsdbPortName(intf | 287 | new OvsdbPortName(intf |
289 | - .getName()), | 288 | + .getName()), |
290 | new OvsdbPortNumber(localPort), | 289 | new OvsdbPortNumber(localPort), |
291 | new OvsdbDatapathId(Long | 290 | new OvsdbDatapathId(Long |
292 | - .toString(dpid)), | 291 | + .toString(dpid)), |
293 | new OvsdbPortType(portType), | 292 | new OvsdbPortType(portType), |
294 | new OvsdbIfaceId(macAndIfaceId[1])); | 293 | new OvsdbIfaceId(macAndIfaceId[1])); |
295 | for (OvsdbEventListener listener : ovsdbEventListener) { | 294 | for (OvsdbEventListener listener : ovsdbEventListener) { |
... | @@ -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 | /** |
... | @@ -349,7 +348,7 @@ public class OvsdbControllerImpl implements OvsdbController { | ... | @@ -349,7 +348,7 @@ public class OvsdbControllerImpl implements OvsdbController { |
349 | * Gets datapathid from table bridge. | 348 | * Gets datapathid from table bridge. |
350 | * | 349 | * |
351 | * @param clientService OvsdbClientService instance | 350 | * @param clientService OvsdbClientService instance |
352 | - * @param dbSchema ovsdb database schema | 351 | + * @param dbSchema ovsdb database schema |
353 | * @return datapathid the bridge datapathid | 352 | * @return datapathid the bridge datapathid |
354 | */ | 353 | */ |
355 | private long getDataPathid(OvsdbClientService clientService, | 354 | private long getDataPathid(OvsdbClientService clientService, | ... | ... |
... | @@ -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,8 +123,9 @@ public final class Row { | ... | @@ -95,8 +123,9 @@ 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 | */ |
101 | public void addColumn(String columnName, Column data) { | 130 | public void addColumn(String columnName, Column data) { |
102 | this.columns.put(columnName, data); | 131 | this.columns.put(columnName, data); | ... | ... |
... | @@ -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 | } | ... | ... |
-
Please register or login to post a comment