Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 1 | package net.floodlightcontroller.topology; |
| 2 | |
| 3 | import java.util.HashMap; |
| 4 | import java.util.HashSet; |
| 5 | import java.util.Map; |
| 6 | import java.util.Set; |
| 7 | |
| 8 | import net.floodlightcontroller.routing.Link; |
| 9 | |
| 10 | import org.openflow.util.HexString; |
| 11 | |
| 12 | public 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 | } |