blob: 606b07914743a1d3cfddf1ab5e9c89f6f32367a0 [file] [log] [blame]
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -08001package net.floodlightcontroller.topology;
2
3import java.util.HashMap;
4import java.util.HashSet;
5import java.util.Map;
6import java.util.Set;
7
8import net.floodlightcontroller.routing.Link;
9
10import org.openflow.util.HexString;
11
12public class Cluster {
13 protected long id; // the lowest id of the nodes
14 protected Map<Long, Set<Link>> links; // set of links connected to a node.
15
16 public Cluster() {
17 id = Long.MAX_VALUE;
18 links = new HashMap<Long, Set<Link>>();
19 }
20
21 public long getId() {
22 return id;
23 }
24
25 public void setId(long id) {
26 this.id = id;
27 }
28
29 public Map<Long, Set<Link>> getLinks() {
30 return links;
31 }
32
33 public Set<Long> getNodes() {
34 return links.keySet();
35 }
36
37 void add(long n) {
38 if (links.containsKey(n) == false) {
39 links.put(n, new HashSet<Link>());
40 if (n < id) id = n;
41 }
42 }
43
44 void addLink(Link l) {
45 if (links.containsKey(l.getSrc()) == false) {
46 links.put(l.getSrc(), new HashSet<Link>());
47 if (l.getSrc() < id) id = l.getSrc();
48 }
49 links.get(l.getSrc()).add(l);
50
51 if (links.containsKey(l.getDst()) == false) {
52 links.put(l.getDst(), new HashSet<Link>());
53 if (l.getDst() < id) id = l.getDst();
54 }
55 links.get(l.getDst()).add(l);
56 }
57
58 @Override
59 public int hashCode() {
60 return (int) (id + id >>>32);
61 }
62
63 @Override
64 public boolean equals(Object obj) {
65 if (this == obj)
66 return true;
67 if (obj == null)
68 return false;
69 if (getClass() != obj.getClass())
70 return false;
71
72 Cluster other = (Cluster) obj;
73 return (this.id == other.id);
74 }
75
76 public String toString() {
77 return "[Cluster id=" + HexString.toHexString(id) + ", " + links.keySet() + "]";
78 }
79}