blob: 898c8ebedb56edd78b67477ae1f9ba3f8df7e545 [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
31 private static final Logger log = LoggerFactory.getLogger(UiTopology.class);
32
33 private final UiCluster uiCluster = new UiCluster();
34 private final Set<UiRegion> uiRegions = new TreeSet<>();
35
Simon Hunt338a3b42016-04-14 09:43:52 -070036 @Override
37 public String toString() {
38 return "Topology: " + uiCluster + ", " + uiRegions.size() + " regions";
39 }
40
Simon Hunt23fb1352016-04-11 12:15:19 -070041 /**
42 * Clears the topology state; that is, drops all regions, devices, hosts,
43 * links, and cluster members.
44 */
45 public void clear() {
46 log.debug("clearing topology model");
47 uiRegions.clear();
48 uiCluster.clear();
49 }
Simon Hunt338a3b42016-04-14 09:43:52 -070050
51 /**
52 * Returns the cluster member with the given identifier, or null if no
53 * such member.
54 *
55 * @param id cluster node identifier
56 * @return the cluster member with that identifier
57 */
58 public UiClusterMember findClusterMember(NodeId id) {
59 return uiCluster.find(id);
60 }
61
62 /**
63 * Adds the given cluster member to the topology model.
64 *
65 * @param member cluster member to add
66 */
67 public void add(UiClusterMember member) {
68 uiCluster.add(member);
69 }
70
71 /**
72 * Returns the number of members in the cluster.
73 *
74 * @return number of cluster members
75 */
76 public int clusterMemberCount() {
77 return uiCluster.size();
78 }
79
80 /**
81 * Returns the number of regions configured in the topology.
82 *
83 * @return number of regions
84 */
85 public int regionCount() {
86 return uiRegions.size();
87 }
Simon Hunt5f6dbf82016-03-30 08:53:33 -070088}