Bri Prebilic Cole

Starting GUI server-side code

Change-Id: Id3d5e198a2326f50ef2661f6971cf23271bf7644
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.core;
18 +
19 +import java.util.Set;
20 +
21 +/**
22 + * Test adapter for core service.
23 + */
24 +public class CoreServiceAdapter implements CoreService {
25 + @Override
26 + public Version version() {
27 + return null;
28 + }
29 +
30 + @Override
31 + public Set<ApplicationId> getAppIds() {
32 + return null;
33 + }
34 +
35 + @Override
36 + public ApplicationId getAppId(Short id) {
37 + return null;
38 + }
39 +
40 + @Override
41 + public ApplicationId registerApplication(String identifier) {
42 + return null;
43 + }
44 +
45 + @Override
46 + public IdGenerator getIdGenerator(String topic) {
47 + return null;
48 + }
49 +}
...@@ -15,15 +15,14 @@ ...@@ -15,15 +15,14 @@
15 */ 15 */
16 package org.onosproject.net.device; 16 package org.onosproject.net.device;
17 17
18 +import com.google.common.base.Predicate;
19 +import com.google.common.collect.FluentIterable;
18 import org.onosproject.net.Device; 20 import org.onosproject.net.Device;
19 import org.onosproject.net.DeviceId; 21 import org.onosproject.net.DeviceId;
20 import org.onosproject.net.MastershipRole; 22 import org.onosproject.net.MastershipRole;
21 import org.onosproject.net.Port; 23 import org.onosproject.net.Port;
22 import org.onosproject.net.PortNumber; 24 import org.onosproject.net.PortNumber;
23 25
24 -import com.google.common.base.Predicate;
25 -import com.google.common.collect.FluentIterable;
26 -
27 import java.util.List; 26 import java.util.List;
28 27
29 /** 28 /**
......
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.flow;
18 +
19 +import org.onosproject.core.ApplicationId;
20 +import org.onosproject.net.DeviceId;
21 +
22 +import java.util.concurrent.Future;
23 +
24 +/**
25 + * Test adapter for flow rule service.
26 + */
27 +public class FlowRuleServiceAdapter implements FlowRuleService {
28 + @Override
29 + public int getFlowRuleCount() {
30 + return 0;
31 + }
32 +
33 + @Override
34 + public Iterable<FlowEntry> getFlowEntries(DeviceId deviceId) {
35 + return null;
36 + }
37 +
38 + @Override
39 + public void applyFlowRules(FlowRule... flowRules) {
40 +
41 + }
42 +
43 + @Override
44 + public void removeFlowRules(FlowRule... flowRules) {
45 +
46 + }
47 +
48 + @Override
49 + public void removeFlowRulesById(ApplicationId appId) {
50 +
51 + }
52 +
53 + @Override
54 + public Iterable<FlowRule> getFlowRulesById(ApplicationId id) {
55 + return null;
56 + }
57 +
58 + @Override
59 + public Iterable<FlowRule> getFlowRulesByGroupId(ApplicationId appId, short groupId) {
60 + return null;
61 + }
62 +
63 + @Override
64 + public Future<CompletedBatchOperation> applyBatch(FlowRuleBatchOperation batch) {
65 + return null;
66 + }
67 +
68 + @Override
69 + public void addListener(FlowRuleListener listener) {
70 +
71 + }
72 +
73 + @Override
74 + public void removeListener(FlowRuleListener listener) {
75 +
76 + }
77 +}
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.intent;
18 +
19 +import java.util.List;
20 +
21 +/**
22 + * Test adapter for intent service.
23 + */
24 +public class IntentServiceAdapter implements IntentService {
25 + @Override
26 + public void submit(Intent intent) {
27 +
28 + }
29 +
30 + @Override
31 + public void withdraw(Intent intent) {
32 +
33 + }
34 +
35 + @Override
36 + public void replace(IntentId oldIntentId, Intent newIntent) {
37 +
38 + }
39 +
40 + @Override
41 + public void execute(IntentOperations operations) {
42 +
43 + }
44 +
45 + @Override
46 + public Iterable<Intent> getIntents() {
47 + return null;
48 + }
49 +
50 + @Override
51 + public long getIntentCount() {
52 + return 0;
53 + }
54 +
55 + @Override
56 + public Intent getIntent(IntentId id) {
57 + return null;
58 + }
59 +
60 + @Override
61 + public IntentState getIntentState(IntentId id) {
62 + return null;
63 + }
64 +
65 + @Override
66 + public List<Intent> getInstallableIntents(IntentId intentId) {
67 + return null;
68 + }
69 +
70 + @Override
71 + public void addListener(IntentListener listener) {
72 +
73 + }
74 +
75 + @Override
76 + public void removeListener(IntentListener listener) {
77 +
78 + }
79 +}
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.statistic;
18 +
19 +import org.onosproject.core.ApplicationId;
20 +import org.onosproject.core.GroupId;
21 +import org.onosproject.net.ConnectPoint;
22 +import org.onosproject.net.Link;
23 +import org.onosproject.net.Path;
24 +import org.onosproject.net.flow.FlowRule;
25 +
26 +import java.util.Optional;
27 +
28 +/**
29 + * Test adapter for statistics service.
30 + */
31 +public class StatisticServiceAdapter implements StatisticService {
32 + @Override
33 + public Load load(Link link) {
34 + return null;
35 + }
36 +
37 + @Override
38 + public Load load(ConnectPoint connectPoint) {
39 + return null;
40 + }
41 +
42 + @Override
43 + public Link max(Path path) {
44 + return null;
45 + }
46 +
47 + @Override
48 + public Link min(Path path) {
49 + return null;
50 + }
51 +
52 + @Override
53 + public FlowRule highestHitter(ConnectPoint connectPoint) {
54 + return null;
55 + }
56 +
57 + @Override
58 + public Load load(Link link, ApplicationId appId, Optional<GroupId> groupId) {
59 + return null;
60 + }
61 +}
...@@ -46,5 +46,11 @@ ...@@ -46,5 +46,11 @@
46 <artifactId>servlet-api</artifactId> 46 <artifactId>servlet-api</artifactId>
47 <version>2.5</version> 47 <version>2.5</version>
48 </dependency> 48 </dependency>
49 + <dependency>
50 + <groupId>org.onosproject</groupId>
51 + <artifactId>onos-api</artifactId>
52 + <scope>test</scope>
53 + <classifier>tests</classifier>
54 + </dependency>
49 </dependencies> 55 </dependencies>
50 </project> 56 </project>
......
...@@ -267,7 +267,7 @@ public class TopologyViewWebSocket ...@@ -267,7 +267,7 @@ public class TopologyViewWebSocket
267 } 267 }
268 268
269 // Sends the specified data to the client. 269 // Sends the specified data to the client.
270 - private synchronized void sendMessage(ObjectNode data) { 270 + protected synchronized void sendMessage(ObjectNode data) {
271 try { 271 try {
272 if (connection.isOpen()) { 272 if (connection.isOpen()) {
273 connection.sendMessage(data.toString()); 273 connection.sendMessage(data.toString());
......
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.gui;
18 +
19 +import com.fasterxml.jackson.databind.node.ObjectNode;
20 +import com.google.common.collect.ImmutableSet;
21 +import org.junit.Before;
22 +import org.junit.Test;
23 +import org.onlab.osgi.ServiceDirectory;
24 +import org.onlab.osgi.TestServiceDirectory;
25 +import org.onlab.packet.ChassisId;
26 +import org.onlab.packet.IpAddress;
27 +import org.onlab.packet.MacAddress;
28 +import org.onlab.packet.VlanId;
29 +import org.onosproject.cluster.ClusterService;
30 +import org.onosproject.cluster.ClusterServiceAdapter;
31 +import org.onosproject.core.CoreService;
32 +import org.onosproject.core.CoreServiceAdapter;
33 +import org.onosproject.core.Version;
34 +import org.onosproject.mastership.MastershipService;
35 +import org.onosproject.mastership.MastershipServiceAdapter;
36 +import org.onosproject.net.DefaultDevice;
37 +import org.onosproject.net.DefaultHost;
38 +import org.onosproject.net.Device;
39 +import org.onosproject.net.DeviceId;
40 +import org.onosproject.net.Host;
41 +import org.onosproject.net.HostId;
42 +import org.onosproject.net.HostLocation;
43 +import org.onosproject.net.Port;
44 +import org.onosproject.net.PortNumber;
45 +import org.onosproject.net.device.DeviceService;
46 +import org.onosproject.net.device.DeviceServiceAdapter;
47 +import org.onosproject.net.flow.FlowEntry;
48 +import org.onosproject.net.flow.FlowRuleService;
49 +import org.onosproject.net.flow.FlowRuleServiceAdapter;
50 +import org.onosproject.net.host.HostService;
51 +import org.onosproject.net.host.HostServiceAdapter;
52 +import org.onosproject.net.intent.IntentService;
53 +import org.onosproject.net.intent.IntentServiceAdapter;
54 +import org.onosproject.net.link.LinkService;
55 +import org.onosproject.net.link.LinkServiceAdapter;
56 +import org.onosproject.net.provider.ProviderId;
57 +import org.onosproject.net.statistic.StatisticService;
58 +import org.onosproject.net.statistic.StatisticServiceAdapter;
59 +import org.onosproject.net.topology.TopologyService;
60 +import org.onosproject.net.topology.TopologyServiceAdapter;
61 +
62 +import java.util.ArrayList;
63 +import java.util.List;
64 +import java.util.Set;
65 +
66 +import static org.junit.Assert.assertEquals;
67 +
68 +public class TopologyViewWebSocketTest {
69 +
70 + private static final ProviderId PID = new ProviderId("of", "foo.bar");
71 + private static final ChassisId CHID = new ChassisId(123L);
72 + private static final MacAddress MAC = MacAddress.valueOf("00:00:00:00:00:19");
73 + private static final DeviceId DID = DeviceId.deviceId("of:foo");
74 + private static final Set<IpAddress> IPS = ImmutableSet.of(IpAddress.valueOf("1.2.3.4"));
75 +
76 + private TestWebSocket ws;
77 + private TestServiceDirectory sd;
78 +
79 + @Before
80 + public void setUp() {
81 + sd = new TestServiceDirectory();
82 + sd.add(DeviceService.class, new TestDeviceService());
83 + sd.add(ClusterService.class, new ClusterServiceAdapter());
84 + sd.add(LinkService.class, new LinkServiceAdapter());
85 + sd.add(HostService.class, new TestHostService());
86 + sd.add(MastershipService.class, new MastershipServiceAdapter());
87 + sd.add(IntentService.class, new IntentServiceAdapter());
88 + sd.add(FlowRuleService.class, new TestFlowService());
89 + sd.add(StatisticService.class, new StatisticServiceAdapter());
90 + sd.add(TopologyService.class, new TopologyServiceAdapter());
91 + sd.add(CoreService.class, new TestCoreService());
92 + ws = new TestWebSocket(sd);
93 + }
94 +
95 + @Test
96 + public void requestDetailsDevice() {
97 + // build the request
98 + String request = "{\"event\":\"requestDetails\", \"sid\":0, "
99 + + "\"payload\":{\"id\":\"of:000001\",\"class\":\"device\"}}";
100 + ws.onMessage(request);
101 + // look at the ws reply, and verify that it is correct
102 + assertEquals("incorrect id", "of:000001", ws.reply.path("payload").path("id").asText());
103 + assertEquals("incorrect mfr", "foo", ws.reply.path("payload").path("props").path("Vendor").asText());
104 + }
105 +
106 + @Test
107 + public void requestDetailsHost() {
108 + // build the request
109 + String request = "{\"event\":\"requestDetails\", \"sid\":0, "
110 + + "\"payload\":{\"id\":\"00:00:00:00:00:19/-1\",\"class\":\"host\"}}";
111 + ws.onMessage(request);
112 + // look at the ws reply, and verify that it is correct
113 + assertEquals("incorrect id", "00:00:00:00:00:19/-1", ws.reply.path("payload").path("id").asText());
114 + assertEquals("incorrect ip address", "1.2.3.4", ws.reply.path("payload").path("props").path("IP").asText());
115 + }
116 +
117 + private class TestWebSocket extends TopologyViewWebSocket {
118 +
119 + private ObjectNode reply;
120 +
121 + /**
122 + * Creates a new web-socket for serving data to GUI topology view.
123 + *
124 + * @param directory service directory
125 + */
126 + public TestWebSocket(ServiceDirectory directory) {
127 + super(directory);
128 + }
129 +
130 + @Override
131 + protected synchronized void sendMessage(ObjectNode data) {
132 + reply = data;
133 + }
134 + }
135 +
136 + private class TestCoreService extends CoreServiceAdapter {
137 + @Override
138 + public Version version() {
139 + return Version.version("1.2.3");
140 + }
141 + }
142 +
143 + private class TestDeviceService extends DeviceServiceAdapter {
144 +
145 + @Override
146 + public Device getDevice(DeviceId deviceId) {
147 + return new DefaultDevice(PID, deviceId, Device.Type.SWITCH,
148 + "foo", "hw", "sw", "sn", CHID);
149 + }
150 +
151 + @Override
152 + public List<Port> getPorts(DeviceId deviceId) {
153 + return new ArrayList<>();
154 + }
155 + }
156 +
157 + private class TestFlowService extends FlowRuleServiceAdapter {
158 + @Override
159 + public Iterable<FlowEntry> getFlowEntries(DeviceId deviceId) {
160 + return new ArrayList<>();
161 + }
162 + }
163 +
164 + private class TestHostService extends HostServiceAdapter {
165 + @Override
166 + public Host getHost(HostId hostId) {
167 + return new DefaultHost(PID, hostId, MAC, VlanId.NONE,
168 + new HostLocation(DID, PortNumber.P0, 123L), IPS);
169 + }
170 + }
171 +}
...\ No newline at end of file ...\ No newline at end of file