blob: 6a76eb59a97d337d1cd6d8a322495a93c67f29a0 [file] [log] [blame]
Simon Huntcda9c032016-04-11 10:32:54 -07001/*
2 * Copyright 2016 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
17package org.onosproject.ui.impl.topo.model;
18
Simon Hunt23fb1352016-04-11 12:15:19 -070019import org.onosproject.cluster.ControllerNode;
20import org.onosproject.cluster.RoleInfo;
Simon Huntcda9c032016-04-11 10:32:54 -070021import org.onosproject.event.EventDispatcher;
22import org.onosproject.net.Device;
Simon Hunt23fb1352016-04-11 12:15:19 -070023import org.onosproject.net.DeviceId;
24import org.onosproject.net.Host;
25import org.onosproject.net.Link;
26import org.onosproject.net.region.Region;
Simon Huntcda9c032016-04-11 10:32:54 -070027import org.onosproject.ui.model.topo.UiDevice;
Simon Hunt23fb1352016-04-11 12:15:19 -070028import org.onosproject.ui.model.topo.UiTopology;
29
30import static org.onosproject.ui.impl.topo.model.UiModelEvent.Type.DEVICE_ADDED;
31import static org.onosproject.ui.impl.topo.model.UiModelEvent.Type.DEVICE_REMOVED;
Simon Huntcda9c032016-04-11 10:32:54 -070032
33/**
34 * UI Topology Model cache.
35 */
36class ModelCache {
37
38 private final EventDispatcher dispatcher;
Simon Hunt23fb1352016-04-11 12:15:19 -070039 private final UiTopology uiTopology = new UiTopology();
Simon Huntcda9c032016-04-11 10:32:54 -070040
41 ModelCache(EventDispatcher eventDispatcher) {
42 this.dispatcher = eventDispatcher;
43 }
44
45 /**
46 * Clear our model.
47 */
48 void clear() {
Simon Hunt23fb1352016-04-11 12:15:19 -070049 uiTopology.clear();
Simon Huntcda9c032016-04-11 10:32:54 -070050 }
51
52 /**
53 * Create our internal model of the global topology.
54 */
55 void load() {
56// loadClusterMembers();
57// loadRegions();
58// loadDevices();
59// loadHosts();
60// loadLinks();
61 }
62
63
Simon Huntcda9c032016-04-11 10:32:54 -070064 void addOrUpdateDevice(Device device) {
Simon Hunt23fb1352016-04-11 12:15:19 -070065 // TODO: find or create device assoc. with parameter
66 // FIXME
Simon Huntcda9c032016-04-11 10:32:54 -070067 UiDevice uiDevice = new UiDevice();
68
Simon Hunt23fb1352016-04-11 12:15:19 -070069 // TODO: post the (correct) event
70 dispatcher.post(new UiModelEvent(DEVICE_ADDED, uiDevice));
Simon Huntcda9c032016-04-11 10:32:54 -070071 }
72
73 void removeDevice(Device device) {
Simon Hunt23fb1352016-04-11 12:15:19 -070074 // TODO: get UiDevice associated with the given parameter; remove from model
75 // FIXME
Simon Huntcda9c032016-04-11 10:32:54 -070076 UiDevice uiDevice = new UiDevice();
77
Simon Hunt23fb1352016-04-11 12:15:19 -070078 // TODO: post the (correct) event
79 dispatcher.post(new UiModelEvent(DEVICE_REMOVED, uiDevice));
Simon Huntcda9c032016-04-11 10:32:54 -070080
81 }
82
Simon Hunt23fb1352016-04-11 12:15:19 -070083 void addOrUpdateClusterMember(ControllerNode cnode) {
84 // TODO: find or create cluster member assoc. with parameter
85 // TODO: post event
86 }
Simon Huntcda9c032016-04-11 10:32:54 -070087
Simon Hunt23fb1352016-04-11 12:15:19 -070088 void removeClusterMember(ControllerNode cnode) {
89 // TODO: find cluster member assoc. with parameter; remove from model
90 // TODO: post event
91 }
92
93
94 void updateMasterships(DeviceId deviceId, RoleInfo roleInfo) {
95 // TODO: store the updated mastership information
96 // TODO: post event
97 }
98
99 void addOrUpdateRegion(Region region) {
100 // TODO: find or create region assoc. with parameter
101 // TODO: post event
102 }
103
104 void removeRegion(Region region) {
105 // TODO: find region assoc. with parameter; remove from model
106 // TODO: post event
107 }
108
109 void addOrUpdateLink(Link link) {
110 // TODO: find ui-link assoc. with parameter; create or update.
111 // TODO: post event
112 }
113
114 void removeLink(Link link) {
115 // TODO: find ui-link assoc. with parameter; update or remove.
116 // TODO: post event
117 }
118
119 void addOrUpdateHost(Host host) {
120 // TODO: find or create host assoc. with parameter
121 // TODO: post event
122 }
123
124 void moveHost(Host host, Host prevHost) {
125 // TODO: process host-move
126 // TODO: post event
127 }
128
129 void removeHost(Host host) {
130 // TODO: find host assoc. with parameter; remove from model
131 }
Simon Huntcda9c032016-04-11 10:32:54 -0700132}