blob: 83792793c0a957c57fb424ba3f3327e83f0d9f78 [file] [log] [blame]
Jonathan Hart472062d2014-04-03 10:56:48 -07001package net.onrc.onos.core.topology;
Jonathan Hart062a2e82014-02-03 09:41:57 -08002
Yuta HIGUCHIdb1b8302014-06-26 10:50:39 -07003import java.util.Map;
4
Yuta HIGUCHI02ccb8c2014-07-10 11:29:45 -07005import net.onrc.onos.core.util.LinkTuple;
6
Yuta HIGUCHIbf0a8712014-06-30 18:59:46 -07007import org.apache.commons.lang.Validate;
Jonathan Hart25bd53e2014-04-30 23:44:09 -07008
Yuta HIGUCHI181d34d2014-02-05 15:05:46 -08009/**
Yuta HIGUCHI8b389a72014-07-18 13:50:00 -070010 * Handler to Link object stored in In-memory Topology snapshot.
Ray Milkey269ffb92014-04-03 14:43:30 -070011 * <p/>
Yuta HIGUCHI181d34d2014-02-05 15:05:46 -080012 */
Jonathan Harte37e4e22014-05-13 19:12:02 -070013public class LinkImpl extends TopologyObject implements Link {
Yuta HIGUCHI181d34d2014-02-05 15:05:46 -080014
Yuta HIGUCHI8b389a72014-07-18 13:50:00 -070015 private final LinkTuple id;
Yuta HIGUCHIbf0a8712014-06-30 18:59:46 -070016
Yuta HIGUCHIbf0a8712014-06-30 18:59:46 -070017
Ray Milkey269ffb92014-04-03 14:43:30 -070018 /**
Yuta HIGUCHI8b389a72014-07-18 13:50:00 -070019 * Creates a Link handler object.
Ray Milkey269ffb92014-04-03 14:43:30 -070020 *
Yuta HIGUCHIbf0a8712014-06-30 18:59:46 -070021 * @param topology Topology instance this object belongs to
Yuta HIGUCHI8b389a72014-07-18 13:50:00 -070022 * @param linkTuple Link identifier
Yuta HIGUCHIbf0a8712014-06-30 18:59:46 -070023 */
Yuta HIGUCHI8b389a72014-07-18 13:50:00 -070024 LinkImpl(TopologyInternal topology, LinkTuple linkTuple) {
Yuta HIGUCHIbf0a8712014-06-30 18:59:46 -070025 super(topology);
Yuta HIGUCHI8b389a72014-07-18 13:50:00 -070026 Validate.notNull(linkTuple);
27 this.id = linkTuple;
Ray Milkey269ffb92014-04-03 14:43:30 -070028 }
Toshio Koide2f570c12014-02-06 16:55:32 -080029
Ray Milkey269ffb92014-04-03 14:43:30 -070030 @Override
Yuta HIGUCHI02ccb8c2014-07-10 11:29:45 -070031 public LinkTuple getLinkTuple() {
Yuta HIGUCHI8b389a72014-07-18 13:50:00 -070032 return id;
Yuta HIGUCHI02ccb8c2014-07-10 11:29:45 -070033 }
34
35 @Override
Ray Milkey269ffb92014-04-03 14:43:30 -070036 public Switch getSrcSwitch() {
Yuta HIGUCHIbf0a8712014-06-30 18:59:46 -070037 topology.acquireReadLock();
38 try {
Yuta HIGUCHI8b389a72014-07-18 13:50:00 -070039 return topology.getSwitch(id.getSrc().getDpid());
Yuta HIGUCHIbf0a8712014-06-30 18:59:46 -070040 } finally {
41 topology.releaseReadLock();
42 }
Ray Milkey269ffb92014-04-03 14:43:30 -070043 }
Pavlin Radoslavov7c8f69a2014-02-19 19:01:45 -080044
Ray Milkey269ffb92014-04-03 14:43:30 -070045 @Override
46 public Port getSrcPort() {
Yuta HIGUCHIbf0a8712014-06-30 18:59:46 -070047 topology.acquireReadLock();
48 try {
Yuta HIGUCHI8b389a72014-07-18 13:50:00 -070049 return topology.getPort(id.getSrc());
Yuta HIGUCHIbf0a8712014-06-30 18:59:46 -070050 } finally {
51 topology.releaseReadLock();
52 }
Ray Milkey269ffb92014-04-03 14:43:30 -070053 }
Pavlin Radoslavov7c8f69a2014-02-19 19:01:45 -080054
Ray Milkey269ffb92014-04-03 14:43:30 -070055 @Override
56 public Switch getDstSwitch() {
Yuta HIGUCHIbf0a8712014-06-30 18:59:46 -070057 topology.acquireReadLock();
58 try {
Yuta HIGUCHI8b389a72014-07-18 13:50:00 -070059 return topology.getSwitch(id.getDst().getDpid());
Yuta HIGUCHIbf0a8712014-06-30 18:59:46 -070060 } finally {
61 topology.releaseReadLock();
62 }
Ray Milkey269ffb92014-04-03 14:43:30 -070063 }
Pavlin Radoslavov7c8f69a2014-02-19 19:01:45 -080064
Ray Milkey269ffb92014-04-03 14:43:30 -070065 @Override
66 public Port getDstPort() {
Yuta HIGUCHIbf0a8712014-06-30 18:59:46 -070067 topology.acquireReadLock();
68 try {
Yuta HIGUCHI8b389a72014-07-18 13:50:00 -070069 return topology.getPort(id.getDst());
Yuta HIGUCHIbf0a8712014-06-30 18:59:46 -070070 } finally {
71 topology.releaseReadLock();
72 }
Ray Milkey269ffb92014-04-03 14:43:30 -070073 }
Jonathan Hart062a2e82014-02-03 09:41:57 -080074
Ray Milkey269ffb92014-04-03 14:43:30 -070075 @Override
76 public long getLastSeenTime() {
77 // TODO Auto-generated method stub
Yuta HIGUCHIbf0a8712014-06-30 18:59:46 -070078 throw new UnsupportedOperationException("Not implemented yet");
Ray Milkey269ffb92014-04-03 14:43:30 -070079 }
Yuta HIGUCHI181d34d2014-02-05 15:05:46 -080080
Ray Milkey269ffb92014-04-03 14:43:30 -070081 @Override
Ray Milkey269ffb92014-04-03 14:43:30 -070082 public Double getCapacity() {
Yuta HIGUCHI8b389a72014-07-18 13:50:00 -070083 return this.topology.getLinkEvent(id).getCapacity();
Ray Milkey269ffb92014-04-03 14:43:30 -070084 }
Toshio Koide0c9106d2014-02-19 15:26:38 -080085
Ray Milkey269ffb92014-04-03 14:43:30 -070086 @Override
Yuta HIGUCHIdb1b8302014-06-26 10:50:39 -070087 public String getStringAttribute(String attr) {
Yuta HIGUCHI8b389a72014-07-18 13:50:00 -070088 return this.topology.getLinkEvent(id).getStringAttribute(attr);
Yuta HIGUCHIdb1b8302014-06-26 10:50:39 -070089 }
90
91 @Override
Yuta HIGUCHIdb1b8302014-06-26 10:50:39 -070092 public String getStringAttribute(String attr, String def) {
93 final String v = getStringAttribute(attr);
94 if (v == null) {
95 return def;
96 } else {
97 return v;
98 }
99 }
100
101 @Override
102 public Map<String, String> getAllStringAttributes() {
Yuta HIGUCHI8b389a72014-07-18 13:50:00 -0700103 return this.topology.getLinkEvent(id).getAllStringAttributes();
Yuta HIGUCHIdb1b8302014-06-26 10:50:39 -0700104 }
105
106 @Override
Ray Milkey269ffb92014-04-03 14:43:30 -0700107 public String toString() {
108 return String.format("%s --(cap:%f Mbps)--> %s",
109 getSrcPort().toString(),
110 getCapacity(),
111 getDstPort().toString());
112 }
Praseed Balakrishnan57ed8432014-06-26 11:49:56 -0700113
114
115 /**
116 * Returns the type of topology object.
117 *
118 * @return the type of the topology object
119 */
120 @Override
121 public String getType() {
Yuta HIGUCHIdbc33122014-07-10 13:32:32 -0700122 return getStringAttribute(TopologyElement.TYPE, TopologyElement.TYPE_PACKET_LAYER);
Praseed Balakrishnan57ed8432014-06-26 11:49:56 -0700123 }
Jonathan Hart062a2e82014-02-03 09:41:57 -0800124}