blob: a8b5b06111ae771319d6ce29c3b1949a6c9f422e [file] [log] [blame]
Simon Hunt5f6dbf82016-03-30 08:53:33 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2016-present Open Networking Laboratory
Simon Hunt5f6dbf82016-03-30 08:53:33 -07003 *
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.model.topo;
18
Simon Hunt338a3b42016-04-14 09:43:52 -070019import org.onosproject.cluster.NodeId;
Simon Hunt23fb1352016-04-11 12:15:19 -070020import org.slf4j.Logger;
21import org.slf4j.LoggerFactory;
22
23import java.util.Set;
24import java.util.TreeSet;
25
Simon Hunt5f6dbf82016-03-30 08:53:33 -070026/**
27 * Represents the overall network topology.
28 */
Simon Huntcda9c032016-04-11 10:32:54 -070029public class UiTopology extends UiElement {
Simon Hunt23fb1352016-04-11 12:15:19 -070030
Simon Hunt642bc452016-05-04 19:34:45 -070031 private static final String DEFAULT_TOPOLOGY_ID = "TOPOLOGY-0";
32
Simon Hunt23fb1352016-04-11 12:15:19 -070033 private static final Logger log = LoggerFactory.getLogger(UiTopology.class);
34
35 private final UiCluster uiCluster = new UiCluster();
36 private final Set<UiRegion> uiRegions = new TreeSet<>();
37
Simon Hunt338a3b42016-04-14 09:43:52 -070038 @Override
39 public String toString() {
40 return "Topology: " + uiCluster + ", " + uiRegions.size() + " regions";
41 }
42
Simon Hunt23fb1352016-04-11 12:15:19 -070043 /**
44 * Clears the topology state; that is, drops all regions, devices, hosts,
45 * links, and cluster members.
46 */
47 public void clear() {
48 log.debug("clearing topology model");
49 uiRegions.clear();
50 uiCluster.clear();
51 }
Simon Hunt338a3b42016-04-14 09:43:52 -070052
53 /**
54 * Returns the cluster member with the given identifier, or null if no
55 * such member.
56 *
57 * @param id cluster node identifier
58 * @return the cluster member with that identifier
59 */
60 public UiClusterMember findClusterMember(NodeId id) {
61 return uiCluster.find(id);
62 }
63
64 /**
65 * Adds the given cluster member to the topology model.
66 *
67 * @param member cluster member to add
68 */
69 public void add(UiClusterMember member) {
70 uiCluster.add(member);
71 }
72
73 /**
Simon Hunt642bc452016-05-04 19:34:45 -070074 * Removes the given cluster member from the topology model.
75 *
76 * @param member cluster member to remove
77 */
78 public void remove(UiClusterMember member) {
79 uiCluster.remove(member);
80 }
81
82 /**
Simon Hunt338a3b42016-04-14 09:43:52 -070083 * Returns the number of members in the cluster.
84 *
85 * @return number of cluster members
86 */
87 public int clusterMemberCount() {
88 return uiCluster.size();
89 }
90
91 /**
92 * Returns the number of regions configured in the topology.
93 *
94 * @return number of regions
95 */
96 public int regionCount() {
97 return uiRegions.size();
98 }
Simon Hunt642bc452016-05-04 19:34:45 -070099
100 @Override
101 public String idAsString() {
102 return DEFAULT_TOPOLOGY_ID;
103 }
Simon Hunt5f6dbf82016-03-30 08:53:33 -0700104}